Skip to content

Commit 06d942e

Browse files
committed
Reject code points between tilde and inverted bang
1 parent aef8c05 commit 06d942e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/lib/chars.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ test('invalid characters', (t) => {
3434
t.regex(invalidChars("dingo'sky"), /Invalid/)
3535
t.regex(invalidChars('dingo\\sky'), /Invalid/)
3636
t.regex(invalidChars('dingo`sky'), /Invalid/)
37-
t.regex(invalidChars('dingo\x7Fsky'), /Invalid/)
37+
t.regex(invalidChars('dingo\u0088sky'), /Invalid/)
3838
})
3939

4040
test('non-unique character', (t) => t.regex(invalidChars('unique'), /not unique/))

src/lib/chars.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ValidChars } from "../types/puid"
1+
import { ValidChars } from '../types/puid'
22

33
/**
44
* Pre-defined character sets
@@ -42,16 +42,17 @@ export const charsName = (chars: string): string => {
4242
}
4343

4444
const validChar = (char: string): boolean => {
45-
const codePoint = codePointOf(char)
45+
const codePointNonBreakSpace = 160
4646

47-
if (160 < codePoint) return true
47+
const codePoint = codePointOf(char)
4848

49-
if (char == '!') return true
50-
if (codePoint < codePointOf('#')) return false
49+
if (codePoint < codePointOf('!')) return false
50+
if (char == '"') return false
5151
if (char == "'") return false
5252
if (char == '\\') return false
5353
if (char == '`') return false
54-
if (codePointOf('~') < codePoint) return false
54+
if (codePoint <= codePointOf('~')) return true
55+
if (codePoint < codePointNonBreakSpace) return false
5556

5657
return true
5758
}

0 commit comments

Comments
 (0)