From f1b352ff6b76cd0b3181a5315d024c0b32cbf9ae Mon Sep 17 00:00:00 2001 From: Taksh Date: Mon, 5 Oct 2026 16:10:52 +0530 Subject: [PATCH 1/3] Recognize combining marks in formatted mentions Split the existing PR change into a smaller reviewable piece. Original change: fix(composer): accept combining marks in @mention regex --- bitchat/Services/MessageFormattingEngine.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bitchat/Services/MessageFormattingEngine.swift b/bitchat/Services/MessageFormattingEngine.swift index 1578f16b..220f83b2 100644 --- a/bitchat/Services/MessageFormattingEngine.swift +++ b/bitchat/Services/MessageFormattingEngine.swift @@ -41,7 +41,9 @@ final class MessageFormattingEngine { enum Patterns { static let hashtag = SafeRegex.compile("#([a-zA-Z0-9_]+)") - static let mention = SafeRegex.compile("@([\\p{L}0-9_]+(?:#[a-fA-F0-9]{4})?)") + // Include \p{M} so NFD nicknames (base letter + combining mark) still + // parse as one mention token; NFC forms are covered by \p{L} alone. + static let mention = SafeRegex.compile("@([\\p{L}\\p{M}0-9_]+(?:#[a-fA-F0-9]{4})?)") /// Trailing partial `@nickname` at the composer cursor — autocomplete only. static let mentionAutocomplete = SafeRegex.compile("@([\\p{L}0-9_]*)$") From e6953f4ef5be20ddac3d3835e0ebd3f6702111c5 Mon Sep 17 00:00:00 2001 From: Taksh Date: Mon, 5 Oct 2026 16:10:52 +0530 Subject: [PATCH 2/3] Resolve normalized composer mentions Split the existing PR change into a smaller reviewable piece. Original change: fix(composer): accept combining marks in @mention regex --- .../ViewModels/ChatComposerCoordinator.swift | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/bitchat/ViewModels/ChatComposerCoordinator.swift b/bitchat/ViewModels/ChatComposerCoordinator.swift index d0d347f2..0e52b3f3 100644 --- a/bitchat/ViewModels/ChatComposerCoordinator.swift +++ b/bitchat/ViewModels/ChatComposerCoordinator.swift @@ -116,6 +116,9 @@ final class ChatComposerCoordinator { } func parseMentions(from content: String) -> [String] { + // Canonicalize before matching so NFD typed text and NFC peer tokens + // share one codepoint sequence (regex also accepts combining marks). + let content = content.precomposedStringWithCanonicalMapping let regex = ChatViewModel.Patterns.mention let nsContent = content as NSString let matches = regex.matches( @@ -125,16 +128,22 @@ final class ChatComposerCoordinator { ) let peerNicknames = context.meshPeerNicknames() - var validTokens = Set(peerNicknames.values) - validTokens.insert(context.nickname) - validTokens.insert(context.nickname + "#" + String(context.myPeerID.id.prefix(4))) + // Key by NFC so a typed combining-accent form still resolves to the + // stored (precomposed) nickname token used on the wire. + var tokensByCanonical = [String: String]() + for token in peerNicknames.values { + tokensByCanonical[token.normalizedNickname] = token + } + tokensByCanonical[context.nickname.normalizedNickname] = context.nickname + let selfSuffix = context.nickname + "#" + String(context.myPeerID.id.prefix(4)) + tokensByCanonical[selfSuffix.normalizedNickname] = selfSuffix var mentions: [String] = [] for match in matches { guard let range = Range(match.range(at: 1), in: content) else { continue } let mentionedName = String(content[range]) - if validTokens.contains(mentionedName) { - mentions.append(mentionedName) + if let canonical = tokensByCanonical[mentionedName.normalizedNickname] { + mentions.append(canonical) } } From c6a747ac13b4ab6518ae4e1647e54c16a54d69de Mon Sep 17 00:00:00 2001 From: Taksh Date: Mon, 5 Oct 2026 16:10:52 +0530 Subject: [PATCH 3/3] Test composed and decomposed mention forms Split the existing PR change into a smaller reviewable piece. Original change: fix(composer): accept combining marks in @mention regex --- .../ChatComposerCoordinatorContextTests.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bitchatTests/ChatComposerCoordinatorContextTests.swift b/bitchatTests/ChatComposerCoordinatorContextTests.swift index d38ddc8a..71272253 100644 --- a/bitchatTests/ChatComposerCoordinatorContextTests.swift +++ b/bitchatTests/ChatComposerCoordinatorContextTests.swift @@ -192,4 +192,16 @@ struct ChatComposerCoordinatorContextTests { ) #expect(Set(mentions) == ["alice", "me", "me#0011"]) } + + @Test @MainActor + func parseMentions_matchesUnicodeEquivalentNicknames() { + let context = MockChatComposerContext() + let coordinator = ChatComposerCoordinator(context: context) + let precomposed = "caf\u{00E9}" + let decomposed = "cafe\u{0301}" + context.meshNicknamesByPeerID = [PeerID(str: "1111111111111111"): precomposed] + + let mentions = coordinator.parseMentions(from: "hi @\(decomposed)") + #expect(mentions == [precomposed]) + } }