Skip to content

Commit b683362

Browse files
committed
fix: avoid matching prototype keys in special char map
1 parent 64c5b5c commit b683362

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/rules/punctuation-unification.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ const generateHandler = (options: Options): Handler => {
9696

9797
const handlerPunctuationUnified = (token: MutableToken) => {
9898
if (token.type === GroupTokenType.GROUP) {
99-
if (charMap[token.modifiedStartValue]) {
99+
if (Object.prototype.hasOwnProperty.call(charMap, token.modifiedStartValue)) {
100100
checkStartValue(
101101
token,
102102
charMap[token.modifiedStartValue],
103103
PUNCTUATION_UNIFICATION
104104
)
105105
}
106-
if (charMap[token.modifiedEndValue]) {
106+
if (Object.prototype.hasOwnProperty.call(charMap, token.modifiedEndValue)) {
107107
checkEndValue(
108108
token,
109109
charMap[token.modifiedEndValue],
@@ -112,7 +112,7 @@ const generateHandler = (options: Options): Handler => {
112112
}
113113
return
114114
} else {
115-
if (charMap[token.modifiedValue]) {
115+
if (Object.prototype.hasOwnProperty.call(charMap, token.modifiedValue)) {
116116
checkValue(
117117
token,
118118
charMap[token.modifiedValue],

test/uncategorized.test.ts

+5
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,9 @@ import ApiIndex from './ApiIndex.vue'
182182
`
183183
expect(getOutput(text, options)).toBe(text)
184184
})
185+
// https://github.com/zhlint-project/zhlint/issues/159
186+
test('#159 unexpected function () { [native code] }', () => {
187+
const text = `p.toString() 中文`
188+
expect(getOutput(text, options)).toBe(text)
189+
})
185190
})

0 commit comments

Comments
 (0)