Skip to content

Commit

Permalink
Merge pull request #160 from zhlint-project/bugfix/159
Browse files Browse the repository at this point in the history
fix: avoid matching prototype keys in special char map
  • Loading branch information
Jinjiang authored Aug 19, 2024
2 parents fb53410 + b683362 commit 95f7b39
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/parser/char.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const newCharTypeSet: { [key in CharType]?: string } = {
[CharType.FULLWIDTH_BRACKET]: '()〔〕[]{}',
[CharType.HALFWIDTH_OTHER_PUNCTUATION]: [
// on-keyboard symbols
'~-+*/\\%=&|"`<>@#$^',
'~-+*/\\%=&|`<>@#$^',
// symbol of death
'†‡'
].join(''),
Expand Down
6 changes: 3 additions & 3 deletions src/rules/punctuation-unification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ const generateHandler = (options: Options): Handler => {

const handlerPunctuationUnified = (token: MutableToken) => {
if (token.type === GroupTokenType.GROUP) {
if (charMap[token.modifiedStartValue]) {
if (Object.prototype.hasOwnProperty.call(charMap, token.modifiedStartValue)) {
checkStartValue(
token,
charMap[token.modifiedStartValue],
PUNCTUATION_UNIFICATION
)
}
if (charMap[token.modifiedEndValue]) {
if (Object.prototype.hasOwnProperty.call(charMap, token.modifiedEndValue)) {
checkEndValue(
token,
charMap[token.modifiedEndValue],
Expand All @@ -112,7 +112,7 @@ const generateHandler = (options: Options): Handler => {
}
return
} else {
if (charMap[token.modifiedValue]) {
if (Object.prototype.hasOwnProperty.call(charMap, token.modifiedValue)) {
checkValue(
token,
charMap[token.modifiedValue],
Expand Down
5 changes: 5 additions & 0 deletions test/uncategorized.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,9 @@ import ApiIndex from './ApiIndex.vue'
`
expect(getOutput(text, options)).toBe(text)
})
// https://github.com/zhlint-project/zhlint/issues/159
test('#159 unexpected function () { [native code] }', () => {
const text = `p.toString() 中文`
expect(getOutput(text, options)).toBe(text)
})
})

0 comments on commit 95f7b39

Please sign in to comment.