Skip to content

Commit 7a7548d

Browse files
JLHwungmathiasbynens
authored andcommitted
Trim trailing spaces from character names
UnicodeData-4.0.0 has trailing spaces after the names of U+02AE and U+0615, which leaked into the generated name keys. Assisted-By: Claude Opus 5.5 Issue: #110
1 parent 2e0a911 commit 7a7548d

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎scripts/parse-names.mjs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ const parseNames = async (version) => {
116116
}
117117
const data = trimmed.split(';');
118118
const codePoint = parseInt(data[0], 16);
119-
const name = data[1];
119+
// Unicode 4.0.0 has trailing spaces after the names of U+02AE and U+0615.
120+
const name = data[1].trim();
120121
if (flag) {
121122
if (/<.+, Last>/.test(name)) {
122123
flag = false;

‎tests/parsers.mjs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ test('Algorithmic ranges have individual formal names', async (t) => {
149149
}
150150
});
151151

152+
test('Names omit trailing spaces from the source data', async (t) => {
153+
const names = await parseNames('4.0.0');
154+
t.assert.ok(
155+
names['LATIN SMALL LETTER TURNED H WITH FISHHOOK'].contains(0x2ae),
156+
);
157+
t.assert.ok(names['ARABIC SMALL HIGH TAH'].contains(0x615));
158+
t.assert.deepEqual(
159+
Object.keys(names).filter((name) => name !== name.trim()),
160+
[],
161+
);
162+
});
163+
152164
test('Unicode 1.1.5 assigns the Unified Han range represented by U+4E00', async (t) => {
153165
const categories = await parseDerivedGeneralCategory('1.1.5');
154166
for (const cp of [0x4e00, 0x4e01, 0x9fa5]) {

0 commit comments

Comments
 (0)