Skip to content

Commit a83db91

Browse files
authored
fix(names): refuse a Bot name that draws nothing (#2879) (#2929)
fix(names): refuse a Bot name that draws nothing (#2879) Fixes #2879 Written-by: Dev-5 Bot: FlyBot Lead Owner: Dev-5 Reviewer: Birfy ## Why `nameProblem()` decided "no name" as `stripInvisible(name).trim() === ''`, which removes only `\p{Cf}` and only White_Space respectively. Characters that are neither survive and draw nothing, so a Bot created with one of them rendered as a nameless Bot on every surface: U+2800 BRAILLE PATTERN BLANK, U+3164 HANGUL FILLER, U+115F HANGUL CHOSEONG FILLER and U+034F COMBINING GRAPHEME JOINER were accepted on the new-Bot form, on creation and on rename. ## Red first With only the new tests and no source change, at the base this branch was cut from (`621e547a`): ``` node --import ./test/harness-resolve.mjs --test test/name-identity.test.js # tests 9 # pass 6 # fail 3 not ok 3 - #2879 a name that draws nothing is refused as empty, whichever characters hide it not ok 4 - #2879 the create path refuses a name that draws nothing and stores none of them not ok 5 - #2879 a rename to a name that draws nothing is refused, and a drawn rename still lands ``` The three failing tests walk U+2800, U+3164, U+115F, U+034F and combinations of them with characters `trim()` does see, through `nameProblem`, `rt.createBot` and `rt.updateBot`. Mutation check on the fix: dropping the new condition from `nameProblem` returns exactly those 3 tests to red (`6 pass / 3 fail`); restoring it is `9/9`, run twice. ## What `nameProblem` now also refuses a name whose characters all draw nothing, with the existing sentence `A Bot needs a name`, so all three entry points answer the same way (`core/src/host/roster.js` create and rename, and the panel's pre-check in `core/src/client/create-bot.js`, which calls the same guard). The class is `[\p{Mn}\p{Me}\p{Zs}\p{Zl}\p{Zp}\p{Default_Ignorable_Code_Point}\u2800]`; U+2800 is not in any of those properties and is listed on its own. `stripInvisible` is unchanged, on purpose: it is the stored-name `\p{Cf}` rule, and widening it would rewrite `De\u2800v` into `Dev` instead of refusing a name nobody can see. A name that draws something keeps the blank it was written with, and the tests hold that. ## Why `core/client.js` is in this diff `core/src/shared/mentions.js` is imported by the client (`core/src/client/create-bot.js:11`), and `core/scripts/build-client.mjs` ships every declaration (`treeShaking: false`). Probed on this base: adding one line `export const __probe = 1` to `mentions.js` makes `node scripts/build-client.mjs --check` fail with `client.js is stale`. So the rule cannot change in one place without rebuilding the committed bundle and its patch. The rebuild is 3 lines of `client.js`; `patches/ds-bot/0001` and the `files/` mirror of the touched test follow from `node scripts/ds-bot-patches.mjs generate`. ## Ran - `TZ=UTC npm run verify` at this head: lint ok, `arch-docs: OK (7 changed file(s))`, `build-client --check` ok, `ds-bot-patches check` and `canonical` ok, core suite **3149/3149**, plugin suites **619 / 149 / 172 / 531 / 147** all green. - That run then reaches `.github/scripts` + `policy`: **674/675**, the one failure `#749: the repository classifies every test file and every workflow`. Every line it prints names `.cache/wt-2547/…`, a detached git worktree of this repository that sits inside the workspace this was built in: not in this diff, absent upstream, and it fails the same way on untouched `main`. - Because `verify` stops at that stage, the rest was run on its own at the same tree: interop 37/37 (lint clean), live-e2e 34/34 (lint clean), `node .github/scripts/changelog.mjs check` → 8 fragments well formed, `core/test/name-identity.test.js` → 9/9 (twice). Not run: smoke (no `core/index.js` or `core/src/host/` change), Desktop, a real-model self-test. ## Base and shas Base `55c5ab48af5de75fbd009c9dab97a74df85fb19c` (live `main` when this was pushed). The push script overlays the branch onto the live base tree, so the pushed head `33b0ef8b6acb6942c02e4d9ba861f0329c3e014a` is not the local commit `965f8963e2978f486df66b1b3215cf716279f19f`: both carry tree `c110813ca0`, and every check below ran on that tree. Docs-not-needed: the name rule is already documented on core-host.md#key-files and the client bundle note on core-client.md; no architecture changed. ## Checkpoint <!-- flybot:checkpoint --> ```json { "pr": 2929, "claim": "Dev-5", "issue": 2879, "summary": "nameProblem() now refuses a Bot name made only of characters that draw nothing — the braille blank, the Hangul fillers and other default-ignorable points — with the existing sentence A Bot needs a name. It refuses at the new-Bot form, on creation and on rename, and stripInvisible is unchanged so a drawn name keeps its blanks. The tests walk each character through nameProblem, createBot and updateBot, and reverting mentions.js to the base blob turns exactly those three tests red. mentions.js ships in the client bundle, so core/client.js and patches/ds-bot/0008 were rebuilt here.", "files": [ "core/src/shared/mentions.js", "core/test/name-identity.test.js", "core/client.js", "patches/ds-bot/0001-core-fixes.patch", "patches/ds-bot/0008-client-bundle.patch", "changelog.d/2879-blank-bot-name.fixed.md" ], "checks": { "ran": "name-identity 9/9; mention-rule+face+flybot-client+client-bundle 47/47; build-client --check ok; ds-bot-patches check ok (this sandbox lacks jsdom, so only those DOM tests did not run; CI tests-ok green at this tip)", "result": "green", "at": "33b0ef8b6acb6942c02e4d9ba861f0329c3e014a" }, "next": "none — PASS at this tip, ready for the merge queue" } ``` <!-- /flybot:checkpoint -->
1 parent 99e0628 commit a83db91

7 files changed

Lines changed: 121 additions & 8 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A Bot name made only of characters that draw nothing is now refused with **A Bot needs a name**, from the new-Bot form, on creation and on rename alike: the braille pattern blank, the Hangul fillers, the combining grapheme joiner and the other default-ignorable code points survive both `\p{Cf}` and `trim()`, so such a name rendered as an empty name. A name that draws something is unaffected, and a name keeps the characters it was written with. See [#2879](https://github.com/ThinkFlowLab/FlyBot/issues/2879).

‎core/client.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2451,9 +2451,10 @@ var LITERAL = /```[\s\S]*?(?:```|$)|`[^`\n]*`|\[[^\]\n]*\]\([^)\s]*(?:\s+(?:"[^"
24512451
var fitsAt = (text2, at, word) => text2.slice(at, at + word.length).toLowerCase() === word.toLowerCase() && !NAME_GOES_ON.test(text2.slice(at + word.length));
24522452
var overlaps = (spans, start, end) => spans.some((span) => start < span.end && span.start < end);
24532453
var stripInvisible = (value) => String(value ?? "").replace(/\p{Cf}/gu, "");
2454+
var NOT_DRAWN = /[\p{Mn}\p{Me}\p{Zs}\p{Zl}\p{Zp}\p{Default_Ignorable_Code_Point}\u2800]/gu;
24542455
function nameProblem(name) {
24552456
const text2 = stripInvisible(name).trim();
2456-
if (text2 === "") return "A Bot needs a name";
2457+
if (text2 === "" || text2.replace(NOT_DRAWN, "").trim() === "") return "A Bot needs a name";
24572458
if (/[@`\r\n]/.test(text2)) return "A Bot name cannot contain @, ` or a line break";
24582459
if (ALL_WORDS.includes(text2.toLowerCase())) return `"${text2}" calls everyone in a group, so it cannot be a Bot name`;
24592460
return void 0;

‎core/src/shared/mentions.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ const overlaps = (spans, start, end) => spans.some(span => start < span.end && s
2222
// (#2691) drops them, and a stored name drops them too, so what is saved is what is shown.
2323
export const stripInvisible = value => String(value ?? '').replace(/\p{Cf}/gu, '')
2424

25+
// What draws nothing is wider than what `stripInvisible` removes: a braille blank, a Hangul
26+
// filler, a combining grapheme joiner, a no-break space and the other default-ignorable code
27+
// points survive both `\p{Cf}` and `trim()`, so a name made of them would render as an empty
28+
// name. A name is refused on them, but they are never stripped out of a name that draws.
29+
const NOT_DRAWN = /[\p{Mn}\p{Me}\p{Zs}\p{Zl}\p{Zp}\p{Default_Ignorable_Code_Point}\u2800]/gu
30+
2531
// What a Bot may be named: something "@" can call without a second reading. A name made
26-
// only of invisible characters reads as no name at all.
32+
// only of characters that draw nothing reads as no name at all (#2879).
2733
export function nameProblem(name) {
2834
const text = stripInvisible(name).trim()
29-
if (text === '') return 'A Bot needs a name'
35+
if (text === '' || text.replace(NOT_DRAWN, '').trim() === '') return 'A Bot needs a name'
3036
if (/[@`\r\n]/.test(text)) return 'A Bot name cannot contain @, ` or a line break'
3137
if (ALL_WORDS.includes(text.toLowerCase())) return `"${text}" calls everyone in a group, so it cannot be a Bot name`
3238
return undefined

‎core/test/name-identity.test.js‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,54 @@ test('#2691 a name of only invisible characters is refused as empty', () => {
9494
assert.equal(nameProblem('Dev\u200b'), undefined)
9595
})
9696

97+
// #2879: `\p{Cf}` and `trim()` cover only part of what draws nothing. A braille blank, a Hangul
98+
// filler and a combining grapheme joiner are neither, so a name made only of them renders as an
99+
// empty name everywhere it is shown. Every entry point refuses it with the same sentence.
100+
const DRAWS_NOTHING = [
101+
'\u2800', // BRAILLE PATTERN BLANK (So)
102+
'\u3164', // HANGUL FILLER (Lo, Default_Ignorable_Code_Point)
103+
'\u115f', // HANGUL CHOSEONG FILLER (Lo, Default_Ignorable_Code_Point)
104+
'\u034f', // COMBINING GRAPHEME JOINER (Mn)
105+
' \u2800 ', // a blank the trim() at either end cannot see
106+
'\u2800\u034f', // two of them together
107+
'\u00a0\u2800', // a no-break space (which trim() does remove) around one it does not
108+
]
109+
const codePoints = name => JSON.stringify([...name].map(character => character.codePointAt(0).toString(16)))
110+
111+
test('#2879 a name that draws nothing is refused as empty, whichever characters hide it', () => {
112+
for (const name of DRAWS_NOTHING) {
113+
assert.equal(nameProblem(name), 'A Bot needs a name', codePoints(name))
114+
}
115+
const blank = '\u2800'
116+
// A name that draws something keeps the character and is still a name.
117+
assert.equal(nameProblem(`De${blank}v`), undefined)
118+
assert.equal(nameProblem('Dev\u2800'), undefined, 'a trailing blank after a drawn name is allowed')
119+
for (const name of ['Dev2', '新 Bot', 'De\u200bv']) assert.equal(nameProblem(name), undefined)
120+
})
121+
122+
test('#2879 the create path refuses a name that draws nothing and stores none of them', async (t) => {
123+
const { rt, state } = setup(t)
124+
await rt.load()
125+
for (const name of DRAWS_NOTHING) {
126+
await assert.rejects(rt.createBot({ name, pickModel: true }), /A Bot needs a name/, codePoints(name))
127+
}
128+
assert.deepEqual(Object.keys(state().bots).sort(), ['cafe', 'chief', 'dev', 'ops'], 'a refused create leaves no record behind')
129+
const created = await rt.createBot({ name: 'De\u2800v', pickModel: true })
130+
assert.equal(created.name, 'De\u2800v', 'a blank between two drawn characters is part of the name')
131+
assert.equal(state().bots[created.id].name, 'De\u2800v')
132+
})
133+
134+
test('#2879 a rename to a name that draws nothing is refused, and a drawn rename still lands', async (t) => {
135+
const { rt, state } = setup(t)
136+
await rt.load()
137+
for (const name of DRAWS_NOTHING) {
138+
await assert.rejects(rt.updateBot('dev', { name }), /A Bot needs a name/, codePoints(name))
139+
}
140+
assert.equal(state().bots.dev.name, 'Dev', 'a refused rename leaves the stored name alone')
141+
await rt.updateBot('dev', { name: 'De\u2800vOps' })
142+
assert.equal(state().bots.dev.name, 'De\u2800vOps')
143+
})
144+
97145
test('#2691 a stored name is found by either canonical spelling or with an invisible character', async (t) => {
98146
const { rt } = setup(t)
99147
await rt.load()

‎patches/ds-bot/0001-core-fixes.patch‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9547,7 +9547,7 @@ diff --git a/src/host/usage.js b/src/host/usage.js
95479547
diff --git a/src/shared/mentions.js b/src/shared/mentions.js
95489548
--- a/src/shared/mentions.js
95499549
+++ b/src/shared/mentions.js
9550-
@@ -16,9 +16,16 @@ const fitsAt = (text, at, word) => text.slice(at, at + word.length).toLowerCase(
9550+
@@ -16,10 +16,23 @@ const fitsAt = (text, at, word) => text.slice(at, at + word.length).toLowerCase(
95519551
&& !NAME_GOES_ON.test(text.slice(at + word.length))
95529552
const overlaps = (spans, start, end) => spans.some(span => start < span.end && span.start < end)
95539553

@@ -9558,14 +9558,22 @@ diff --git a/src/shared/mentions.js b/src/shared/mentions.js
95589558
+// (#2691) drops them, and a stored name drops them too, so what is saved is what is shown.
95599559
+export const stripInvisible = value => String(value ?? '').replace(/\p{Cf}/gu, '')
95609560
+
9561+
+// What draws nothing is wider than what `stripInvisible` removes: a braille blank, a Hangul
9562+
+// filler, a combining grapheme joiner, a no-break space and the other default-ignorable code
9563+
+// points survive both `\p{Cf}` and `trim()`, so a name made of them would render as an empty
9564+
+// name. A name is refused on them, but they are never stripped out of a name that draws.
9565+
+const NOT_DRAWN = /[\p{Mn}\p{Me}\p{Zs}\p{Zl}\p{Zp}\p{Default_Ignorable_Code_Point}\u2800]/gu
9566+
+
95619567
+// What a Bot may be named: something "@" can call without a second reading. A name made
9562-
+// only of invisible characters reads as no name at all.
9568+
+// only of characters that draw nothing reads as no name at all (#2879).
95639569
export function nameProblem(name) {
95649570
- const text = String(name ?? '').trim()
9571+
- if (text === '') return 'A Bot needs a name'
95659572
+ const text = stripInvisible(name).trim()
9566-
if (text === '') return 'A Bot needs a name'
9573+
+ if (text === '' || text.replace(NOT_DRAWN, '').trim() === '') return 'A Bot needs a name'
95679574
if (/[@`\r\n]/.test(text)) return 'A Bot name cannot contain @, ` or a line break'
95689575
if (ALL_WORDS.includes(text.toLowerCase())) return `"${text}" calls everyone in a group, so it cannot be a Bot name`
9576+
return undefined
95699577
@@ -63,3 +63,24 @@ export function mentionSpans(text, bots, { references = [] } = {}) {
95709578
}
95719579
return spans

‎patches/ds-bot/0008-client-bundle.patch‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ diff --git a/client.js b/client.js
17631763
var maskBox = (size) => `maskUnits="userSpaceOnUse" x="${-size}" y="${-size}" width="${size * 3}" height="${size * 3}"`;
17641764
var holes = (def, eyes) => `<rect x="${-def.size}" y="${-def.size}" width="${def.size * 3}" height="${def.size * 3}" fill="#fff"/>${eyes}`;
17651765
var MASK_ID = "%MASK%";
1766-
@@ -1242,227 +1242,144 @@ function maskOf(shape) {
1766+
@@ -1242,227 +1242,145 @@ function maskOf(shape) {
17671767
}
17681768
var DEFAULT_MASK = maskOf(FALLBACK_SHAPE);
17691769

@@ -1811,9 +1811,10 @@ diff --git a/client.js b/client.js
18111811
+var fitsAt = (text2, at, word) => text2.slice(at, at + word.length).toLowerCase() === word.toLowerCase() && !NAME_GOES_ON.test(text2.slice(at + word.length));
18121812
+var overlaps = (spans, start, end) => spans.some((span) => start < span.end && span.start < end);
18131813
+var stripInvisible = (value) => String(value ?? "").replace(/\p{Cf}/gu, "");
1814+
+var NOT_DRAWN = /[\p{Mn}\p{Me}\p{Zs}\p{Zl}\p{Zp}\p{Default_Ignorable_Code_Point}\u2800]/gu;
18141815
+function nameProblem(name) {
18151816
+ const text2 = stripInvisible(name).trim();
1816-
+ if (text2 === "") return "A Bot needs a name";
1817+
+ if (text2 === "" || text2.replace(NOT_DRAWN, "").trim() === "") return "A Bot needs a name";
18171818
+ if (/[@`\r\n]/.test(text2)) return "A Bot name cannot contain @, ` or a line break";
18181819
+ if (ALL_WORDS.includes(text2.toLowerCase())) return `"${text2}" calls everyone in a group, so it cannot be a Bot name`;
18191820
+ return void 0;

‎patches/ds-bot/files/test/name-identity.test.js‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,54 @@ test('#2691 a name of only invisible characters is refused as empty', () => {
9494
assert.equal(nameProblem('Dev\u200b'), undefined)
9595
})
9696

97+
// #2879: `\p{Cf}` and `trim()` cover only part of what draws nothing. A braille blank, a Hangul
98+
// filler and a combining grapheme joiner are neither, so a name made only of them renders as an
99+
// empty name everywhere it is shown. Every entry point refuses it with the same sentence.
100+
const DRAWS_NOTHING = [
101+
'\u2800', // BRAILLE PATTERN BLANK (So)
102+
'\u3164', // HANGUL FILLER (Lo, Default_Ignorable_Code_Point)
103+
'\u115f', // HANGUL CHOSEONG FILLER (Lo, Default_Ignorable_Code_Point)
104+
'\u034f', // COMBINING GRAPHEME JOINER (Mn)
105+
' \u2800 ', // a blank the trim() at either end cannot see
106+
'\u2800\u034f', // two of them together
107+
'\u00a0\u2800', // a no-break space (which trim() does remove) around one it does not
108+
]
109+
const codePoints = name => JSON.stringify([...name].map(character => character.codePointAt(0).toString(16)))
110+
111+
test('#2879 a name that draws nothing is refused as empty, whichever characters hide it', () => {
112+
for (const name of DRAWS_NOTHING) {
113+
assert.equal(nameProblem(name), 'A Bot needs a name', codePoints(name))
114+
}
115+
const blank = '\u2800'
116+
// A name that draws something keeps the character and is still a name.
117+
assert.equal(nameProblem(`De${blank}v`), undefined)
118+
assert.equal(nameProblem('Dev\u2800'), undefined, 'a trailing blank after a drawn name is allowed')
119+
for (const name of ['Dev2', '新 Bot', 'De\u200bv']) assert.equal(nameProblem(name), undefined)
120+
})
121+
122+
test('#2879 the create path refuses a name that draws nothing and stores none of them', async (t) => {
123+
const { rt, state } = setup(t)
124+
await rt.load()
125+
for (const name of DRAWS_NOTHING) {
126+
await assert.rejects(rt.createBot({ name, pickModel: true }), /A Bot needs a name/, codePoints(name))
127+
}
128+
assert.deepEqual(Object.keys(state().bots).sort(), ['cafe', 'chief', 'dev', 'ops'], 'a refused create leaves no record behind')
129+
const created = await rt.createBot({ name: 'De\u2800v', pickModel: true })
130+
assert.equal(created.name, 'De\u2800v', 'a blank between two drawn characters is part of the name')
131+
assert.equal(state().bots[created.id].name, 'De\u2800v')
132+
})
133+
134+
test('#2879 a rename to a name that draws nothing is refused, and a drawn rename still lands', async (t) => {
135+
const { rt, state } = setup(t)
136+
await rt.load()
137+
for (const name of DRAWS_NOTHING) {
138+
await assert.rejects(rt.updateBot('dev', { name }), /A Bot needs a name/, codePoints(name))
139+
}
140+
assert.equal(state().bots.dev.name, 'Dev', 'a refused rename leaves the stored name alone')
141+
await rt.updateBot('dev', { name: 'De\u2800vOps' })
142+
assert.equal(state().bots.dev.name, 'De\u2800vOps')
143+
})
144+
97145
test('#2691 a stored name is found by either canonical spelling or with an invisible character', async (t) => {
98146
const { rt } = setup(t)
99147
await rt.load()

0 commit comments

Comments
 (0)