Skip to content

Commit 7bf2dec

Browse files
committed
refactor: store invisible characters as escapes in registry and tests
INVISIBLE_CHARACTERS held the six characters as raw literals while a neighboring comment claimed the module used escapes to keep the source readable. Switch the registry and its test file to explicit \uXXXX escapes so the comment matches reality and each code point is verifiable in a diff.
1 parent 75c40f9 commit 7bf2dec

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

webapp/src/fixtures/__tests__/invisibleCharacters.test.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,52 +30,52 @@ describe('findInvisibleCharacters', () => {
3030
});
3131

3232
it.each([
33-
[' ', 'nonBreakingSpace'],
34-
['', 'nonBreakingSpace'],
35-
['', 'nonBreakingSpace'],
36-
['', 'zeroWidth'],
37-
['', 'zeroWidth'],
38-
['­', 'zeroWidth'],
33+
['\u00A0', 'nonBreakingSpace'],
34+
['\u202F', 'nonBreakingSpace'],
35+
['\u2007', 'nonBreakingSpace'],
36+
['\u200B', 'zeroWidth'],
37+
['\uFEFF', 'zeroWidth'],
38+
['\u00AD', 'zeroWidth'],
3939
])('finds %j and reports kind %s', (value, kind) => {
4040
expect(findInvisibleCharacters(`a${value}b`)).toEqual([
4141
{ index: 1, char: { value, kind } },
4242
]);
4343
});
4444

4545
it('finds a character at the first index', () => {
46-
expect(findInvisibleCharacters(' abc')).toEqual([
47-
{ index: 0, char: { value: ' ', kind: 'nonBreakingSpace' } },
46+
expect(findInvisibleCharacters('\u00A0abc')).toEqual([
47+
{ index: 0, char: { value: '\u00A0', kind: 'nonBreakingSpace' } },
4848
]);
4949
});
5050

5151
it('finds a character at the last index', () => {
52-
expect(findInvisibleCharacters('abc ')).toEqual([
53-
{ index: 3, char: { value: ' ', kind: 'nonBreakingSpace' } },
52+
expect(findInvisibleCharacters('abc\u00A0')).toEqual([
53+
{ index: 3, char: { value: '\u00A0', kind: 'nonBreakingSpace' } },
5454
]);
5555
});
5656

5757
it('finds multiple characters in ascending order', () => {
58-
expect(findInvisibleCharacters('a b​c')).toEqual([
59-
{ index: 1, char: { value: ' ', kind: 'nonBreakingSpace' } },
60-
{ index: 3, char: { value: '', kind: 'zeroWidth' } },
58+
expect(findInvisibleCharacters('a\u00A0b\u200Bc')).toEqual([
59+
{ index: 1, char: { value: '\u00A0', kind: 'nonBreakingSpace' } },
60+
{ index: 3, char: { value: '\u200B', kind: 'zeroWidth' } },
6161
]);
6262
});
6363

6464
it('finds adjacent characters', () => {
65-
expect(findInvisibleCharacters('  ')).toEqual([
66-
{ index: 0, char: { value: ' ', kind: 'nonBreakingSpace' } },
67-
{ index: 1, char: { value: ' ', kind: 'nonBreakingSpace' } },
65+
expect(findInvisibleCharacters('\u00A0\u00A0')).toEqual([
66+
{ index: 0, char: { value: '\u00A0', kind: 'nonBreakingSpace' } },
67+
{ index: 1, char: { value: '\u00A0', kind: 'nonBreakingSpace' } },
6868
]);
6969
});
7070

7171
it('reports code-unit offsets in text containing surrogate pairs', () => {
72-
expect(findInvisibleCharacters('\u{1f600} ')).toEqual([
73-
{ index: 2, char: { value: ' ', kind: 'nonBreakingSpace' } },
72+
expect(findInvisibleCharacters('\u{1f600}\u00A0')).toEqual([
73+
{ index: 2, char: { value: '\u00A0', kind: 'nonBreakingSpace' } },
7474
]);
7575
});
7676

7777
it('is stable across repeated calls', () => {
78-
const text = 'a b';
78+
const text = 'a\u00A0b';
7979
expect(findInvisibleCharacters(text)).toEqual(
8080
findInvisibleCharacters(text)
8181
);

webapp/src/fixtures/invisibleCharacters.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ export type InvisibleChar = {
66
};
77

88
export const INVISIBLE_CHARACTERS: InvisibleChar[] = [
9-
{ value: ' ', kind: 'nonBreakingSpace' },
10-
{ value: '', kind: 'nonBreakingSpace' },
11-
{ value: '', kind: 'nonBreakingSpace' },
12-
{ value: '', kind: 'zeroWidth' },
13-
{ value: '', kind: 'zeroWidth' },
14-
{ value: '­', kind: 'zeroWidth' },
9+
{ value: '\u00A0', kind: 'nonBreakingSpace' },
10+
{ value: '\u202F', kind: 'nonBreakingSpace' },
11+
{ value: '\u2007', kind: 'nonBreakingSpace' },
12+
{ value: '\u200B', kind: 'zeroWidth' },
13+
{ value: '\uFEFF', kind: 'zeroWidth' },
14+
{ value: '\u00AD', kind: 'zeroWidth' },
1515
];
1616

1717
const BY_VALUE = new Map(

0 commit comments

Comments
 (0)