Skip to content

Commit

Permalink
fix: skip ascii symbol in process (#31)
Browse files Browse the repository at this point in the history
* fix: skip ascii symbol in process

* fix: skip printable ASCII symbol

* move printable ASCII symbol check after case fold
  • Loading branch information
JLHwung committed Sep 29, 2023
1 parent b278ed4 commit 55f3e5e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions rewrite-pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,10 @@ const processTerm = (item, regenerateOptions, groups) => {
const codePoint = item.codePoint;
const set = regenerate(codePoint);
const folded = maybeFold(codePoint);
if (folded.length === 1 && item.kind === "symbol" && folded[0] >= 0x20 && folded[0] <= 0x7E) {
// skip regenerate when it is a printable ASCII symbol
break;
}
set.add(folded);
update(item, set.toString(regenerateOptions));
break;
Expand Down
6 changes: 6 additions & 0 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ describe('unicodePropertyEscapes', () => {
'\\u03B8'
);
});
it('should not replace `-` symbol when not in character class range', () => {
assert.equal(
rewritePattern('-'),
'-'
)
})
});

describe('dotAllFlag', () => {
Expand Down

0 comments on commit 55f3e5e

Please sign in to comment.