Repository navigation
Co-Work: a name keeps no format characters, from the LAN too - #439
Merged
Merged
Conversation
A name was cleaned of control characters only, so U+202E (a right-to-left
override), zero-width spaces and joiners, a soft hyphen, a byte-order mark and
an isolate all survived: "Bo" followed by an override draws as "oB", and a
zero-width space makes one person's name the same pixels as another's, in the
people list and in a knock's dialog.
Names are now cleaned of Unicode's format characters (the Cf category) too, by
one helper, host::clean, which the hello, the knock, the host's name a guest
keeps and both copies of the people list use; the guest's copy had a second
inline rule of its own. Truncation to MAX_NAME still counts characters, and a
name left with nothing is the fallback it was ("Guest", "the host").
Tested by tests::a_name_keeps_no_invisible_format_characters_and_an_honest_one_is_kept:
an override, a zero-width space, a soft hyphen, a BOM and an isolate come out, a
name of nothing but them is "Guest", Jose with an accent, a Chinese character
and an emoji are kept unchanged, and a long name is cut to MAX_NAME characters.
The crate's 27 tests pass, as do the gate's fmt, i18n and clippy.
No FORMAT change: nothing new is written to a file, and an older build reads
these names as it always did.
The Join list read a host's name and project from a UDP answer that nothing
authenticates, with a length cap only, and showed them as "name · project ·
addr": a U+202E in the name reversed the rest of that row, so the address the
user reads was wrong. Both now go through host::clean, which also gains the cap
as an argument so a project of up to 200 characters keeps them instead of being
cut to MAX_NAME; the tag, port and version are still read strictly, so a
datagram that isn't an answer is passed over. A missing name is "the host", a
missing project "a project", rather than the row disappearing.
The tests are red assertions now, not a compile error. The hello test puts a
U+202E in the guest's name and asserts the joined name does not contain it; the
LAN test forges "Ana · House" and "José · Casa 李" and asserts the first is
cleaned and the second kept; the cleaning test gains U+06DD, U+E0041 and
U+1BCA0, one per range a typo in the list would miss.
is_format splits '\u{2060}'..='\u{206F}' into 2060..=2064 and 2066..=206F:
U+2065 is unassigned, and the comment claimed the range was format characters.
The wording follows: clean and docs/areas/cowork.md say "no control or format
characters" rather than "invisible" ones, because U+0600, U+06DD and U+070F are
Cf and do show, and is_format says most are invisible while those few go too.
A name that joins emoji with U+200D is therefore no longer one glyph: that is a
deliberate line, and it is in the PR body's "Not done".
Tested by the gate (fmt, i18n, clippy of cowork, core and the UI, the cleaning
test) and by the crate's 27 tests. No FORMAT change: nothing new is written to a
file, and an older build reads these names as it did.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
A display name was cleaned of control characters only, so it kept every Unicode format character (the
Cfgeneral category): U+202E RIGHT-TO-LEFT OVERRIDE, U+200B ZERO WIDTH SPACE, U+00AD SOFT HYPHEN, U+FEFF ZERO
WIDTH NO-BREAK SPACE, U+2066..U+2069 BIDI ISOLATES and the rest. Those characters mostly draw as nothing yet
change what is drawn around them, so a guest could show
Bo<U+202E>(which rendersoB), or a nameindistinguishable from another participant's: in the host's people list, in the guests' copy of it, in the
knock dialog and in each other's cursor labels. This is impersonation, not cosmetics.
The same gap was one row wider: the Join list (
crates/ui-egui/src/cowork.rs) shows a host it found on theLAN as
"{name} · {project} · {addr}", anddiscovery::foundread those two from a UDP answer nothingauthenticates, with a length cap only. A U+202E in that name reversed the rest of the row, so the address
the user reads was not the address shown. Both are now cleaned the same way.
Names are filtered of control and format characters by one helper, so there is no second cleaner with a
different rule.
Behaviour
host::clean(name, max, fallback)(pub(crate)) filtersc.is_control() || is_format(c), trims, cuts tomaxcharacters and falls back when nothing is left.is_formatis an explicit list of theCfranges(U+2060..U+2064 and U+2066..U+206F listed separately, since U+2065 is unassigned), because std has no
general-category test and the crate takes no regex dependency.
host.rs), a knock's name (host.rs), thehost's name a guest keeps from the welcome and from a
movedhandover (live.rs), both copies of the peoplelist — the host's (
HostEvent::Joined) and the guest's (Joined::take, wherelive.rshad an inline closurewith a rule of its own, and no trimming) — and now discovery's
nameandproject.maxis an argument rather thanMAX_NAME, so discovery keeps its own caps: 40 characters for a host's name,200 for a project (a project longer than 40 used to keep its length and now still does). A name that is too
long, or that is not a string at all, no longer drops the answer from the list: it is cut or falls back to
"the host"/"a project", which is what the Join row needs. The tag, the port and the version are stillread strictly, so a datagram that is not an answer is passed over.
characters only.
File compatibility
None. No field, no default and nothing written changes, so
FORMATstays as it is and an older build readsthese names exactly as it did.
MAX_NAMEand the"Guest"fallback are unchanged.Tests
tests::a_name_keeps_no_invisible_format_characters_and_an_honest_one_is_kept(
crates/cowork/src/tests.rs):Bo+ U+202E + U+200B + U+00AD + U+FEFF comes outBo; U+2066 / U+2069around it come out
Bo; a name of nothing but them isGuest; U+06DD, U+E0041 and U+1BCA0 (one from theArabic marks, the tags and the shorthand) go too, so a typo in those ranges fails;
José,李andAna 🏠come back unchanged; a name in a 3-byte-per-character script is cut to
MAX_NAMEcharacters, not bytes.tests::a_hello_is_read_strictly_and_its_name_made_safe: the hello's name now carries a U+202E and the testasserts the joined name does not contain it — a red assertion on the old code, not only a compile error —
beside the existing check that no control character survives, the cut and
starts_with("Bo").tests::a_guest_finds_a_host_on_the_lan_by_its_code_and_ignores_junk: a forgedhereanswer carryingAn<U+202E>a/Ho<U+200B>useis listed asAna/House, and an honestJosé/Casa 李beside itarrives unchanged. This failed on the previous commit with
[("An\u{202e}a", "Ho\u{200b}use"), ("José", "Casa 李")]— red before the fix, green after.cargo test -p bimcraft-cowork), and the gate —notes/verify.ps1 -TestFilter a_name_keeps_no_invisible_format_characters— passed:cargo fmt --check,cargo i18n check, clippy ofbimcraft-cowork, core and the UI (thedocs/edit pulls the last two in), andthe focused tests. The
.potwas not touched: no interface string was added.Note for a reviewer: no visual coverage — a label's rendering of these characters is not something a unit test
sees; the call sites are the whole of the rule, and
is_controlincrates/coworknow appears only in errortext (
guest.rs,knock.rs, see Not done) and in the tag/version check ofdiscovery.rs.Not done
Аnawith a CyrillicАis a different string and stays as it is; tellingpeople apart by script or by comparing names is a policy, not a filter, and two guests can also still choose
the same visible name on purpose.
Cfand goes with the rest, so👩💻arrives as👩💻— two emoji. Deliberate: a joiner is also what hides a sequence, and a name is notworth an exception.
Cfcharacters do show and go anyway: U+0600 ARABIC NUMBER SIGN, U+06DD ARABIC END OF AYAH,U+070F SYRIAC ABBREVIATION MARK. A name needs none of them, and the rule is the category, not "invisible".
endedreasons are still filtered withis_controlonly (guest.rs,knock.rs): they are sentences in adialog rather than a name, and the same reordering applies, but changing them is its own decision about error
text; not this PR.
Zl/Zp, notCf) are not removed; they draw asa break rather than as nothing, so they do not hide a name, but a label containing one still looks odd.