Skip to content

Commit 95f7b39

Browse files
authored
Merge pull request #160 from zhlint-project/bugfix/159
fix: avoid matching prototype keys in special char map
2 parents fb53410 + b683362 commit 95f7b39

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/parser/char.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const newCharTypeSet: { [key in CharType]?: string } = {
2727
[CharType.FULLWIDTH_BRACKET]: '()〔〕[]{}',
2828
[CharType.HALFWIDTH_OTHER_PUNCTUATION]: [
2929
// on-keyboard symbols
30-
'~-+*/\\%=&|"`<>@#$^',
30+
'~-+*/\\%=&|`<>@#$^',
3131
// symbol of death
3232
'†‡'
3333
].join(''),

src/rules/punctuation-unification.ts

Lines changed: 3 additions & 3 deletions
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

Lines changed: 5 additions & 0 deletions
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)