mirror of
https://github.com/block/buzz.git
synced 2026-11-24 10:12:19 +00:00
fix(mobile): fold accents when matching mention names
`@jos` listed José María, `@jose` listed nobody and `@josé` listed them again: mobile only lowercased names. Name matching now follows section 3 of the shared mention rules, as buzz-app does (recommendation 6). Each code point is NFKD-normalized, its combining accents (the Combining Diacritical Marks blocks) are removed, it is lowercased and a final `ς` becomes `σ`, so `jose` matches `José`, `fiona` matches `fio` and `jose` matches `jose`, while `ø`, `ł`, `æ`, `ß`, `ı` and the marks of other scripts stay distinct. Words are runs of letters, marks and digits, so a hyphen or apostrophe separates them: `jane` finds `Mary-Jane` and `brien` finds `O'Brien`. The folding lives in `name_match.dart` and drives the chooser, Space selection, multi-word admission, the verified-name matches and the recipient pickers, so `@jose maria` lists José María with no accents typed. The vendored fixture moves from version 1 (95 cases) to version 4 of buzz-app's `mention-rules.fixtures.json` (125 cases), copied unchanged, and the conformance test runs every section, with a new `matching` group. No case is skipped. The rules the newer versions added are implemented too: an exact public key (64 hex in either case, or a complete lowercase or uppercase npub with an optional `nostr:` prefix) matches only its owner, even one with no name, and Space selects that owner; the viewer's own agent whose name continues the query with a new word leads (`Sol 6` for `sol`), and an exact person leads over it; agents from the viewer's other communities follow everyone here; an outside choice's longer name no longer blocks a member's exact name on Space, and a choice's own longer alias is not its own namesake. The search cache's exact-key exemption uses the same `typedPublicKey`. Refutation itself stays lowercase-only on purpose: it reasons about the relay's prefix search, which is out of scope here, so an accented query is a new search rather than a continuation. A refuted query still matches members on the device by folding: after `z` finds nobody, `@zoe` lists the member Zoë without a search. Tests: the compose bar search journey types `@jose maria` and sees José María, and `@zoe` after the `z` refutation sees Zoë; both and seven fixture cases fail when accent stripping is removed. `dart format`, `flutter analyze` and the full mobile `flutter test` suite pass. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Matt Toohey <contact@matttoohey.com>
This commit is contained in:
@@ -7,8 +7,9 @@ part of '../compose_bar_test.dart';
|
||||
void mentionSearchTests() {
|
||||
final bob = 'b' * 64;
|
||||
final alice = 'a' * 64;
|
||||
final zoe = '9' * 64;
|
||||
final members = [
|
||||
for (final (key, name) in [(bob, 'Bob'), (alice, 'Alice')])
|
||||
for (final (key, name) in [(bob, 'Bob'), (alice, 'Alice'), (zoe, 'Zoë')])
|
||||
ChannelMember(
|
||||
pubkey: key,
|
||||
displayName: name,
|
||||
@@ -107,13 +108,15 @@ void mentionSearchTests() {
|
||||
|
||||
// Multi-word names are searched word by word: a second word that
|
||||
// continues no local name still goes to the directory, and one that
|
||||
// continues a found name keeps that person listed.
|
||||
// continues a found name keeps that person listed. Names fold accents
|
||||
// (section 3, recommendation 6): `jose maria` lists José María.
|
||||
searched.clear();
|
||||
await tester.enterText(field, '');
|
||||
await tester.pump();
|
||||
await type(tester, '', '@jos mar');
|
||||
await type(tester, '', '@jose maria');
|
||||
expect(searched, contains('jos'));
|
||||
expect(searched.last, 'jos mar');
|
||||
expect(searched.last, 'jose maria');
|
||||
expect(row('José María'), findsOneWidget);
|
||||
searched.clear();
|
||||
await tester.enterText(field, '');
|
||||
await tester.pump();
|
||||
@@ -122,11 +125,19 @@ void mentionSearchTests() {
|
||||
expect(row('Alice Smith'), findsOneWidget);
|
||||
|
||||
// Once a search finds nobody, longer queries are refuted: no search,
|
||||
// and the chooser closes. The same query searches again when it is
|
||||
// and the chooser closes. A refuted query still matches members on the
|
||||
// device, folding accents: `@zoe` lists the member Zoë after `z` found
|
||||
// nobody in the directory. The same query searches again when it is
|
||||
// typed afresh.
|
||||
searched.clear();
|
||||
await tester.enterText(field, '');
|
||||
await tester.pump();
|
||||
await type(tester, '', '@zoe');
|
||||
expect(searched.where((q) => q.isNotEmpty), ['z']);
|
||||
expect(row('Zoë'), findsOneWidget);
|
||||
searched.clear();
|
||||
await tester.enterText(field, '');
|
||||
await tester.pump();
|
||||
await type(tester, '', '@z');
|
||||
expect(searched.where((q) => q.isNotEmpty), ['z']);
|
||||
searched.clear();
|
||||
|
||||
Reference in New Issue
Block a user