Skip to content

Commit f29c270

Browse files
committed
fix(regex): escape more characters in character classes
1 parent 2001028 commit f29c270

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/regex.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ const matchK = match.on('kind').w
99

1010
const repr = (n: number): string =>
1111
// < 32 -> control characters
12-
// 45 -> '-'.. seems like `/[--z]/` for example actually works, but looks weird.
12+
// 45 -> '-'.. seems like `/[--z]/` for example actually works, but looks
13+
// weird.
14+
// 47 -> '/' doesn't need to be escaped in JS, but it's helpful for copying
15+
// into regex debuggers since it must be escaped in some languages
16+
// 92 -> '\' just to avoid any issues with escaping
1317
// 93 -> ']' which needs to be escaped
1418
// 94 -> '^' which might get parsed as class exclusion marker, so escape just in case
1519
// 127 -> del
1620
// >127 -> outside normal ascii range. escape 'em
17-
n < 32 || n === 45 || n === 93 || n === 94 || n >= 127
21+
n < 32 || n === 45 || n === 47 || n === 92 || n === 93 || n === 94 || n >= 127
1822
? n > 255
1923
? `\\u${n.toString(16).padStart(4, '0')}`
2024
: `\\x${n.toString(16).padStart(2, '0')}`

0 commit comments

Comments
 (0)