From 8d76f5d012354e9bddec9e40714b85def4379093 Mon Sep 17 00:00:00 2001 From: jack Date: Thu, 11 Sep 2025 20:59:21 +0200 Subject: [PATCH] Trim trailing/leading spaces in geohash nicknames and tag emission Sanitize Nostr 'n' tag values on ingest and emit by trimming whitespace/newlines to prevent trailing spaces in displayed usernames. Local nickname is already trimmed on focus loss and submit. --- bitchat/Nostr/NostrProtocol.swift | 2 +- bitchat/ViewModels/ChatViewModel.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bitchat/Nostr/NostrProtocol.swift b/bitchat/Nostr/NostrProtocol.swift index 4919b183..7ca4300a 100644 --- a/bitchat/Nostr/NostrProtocol.swift +++ b/bitchat/Nostr/NostrProtocol.swift @@ -107,7 +107,7 @@ struct NostrProtocol { teleported: Bool = false ) throws -> NostrEvent { var tags = [["g", geohash]] - if let nickname = nickname, !nickname.isEmpty { + if let nickname = nickname?.trimmingCharacters(in: .whitespacesAndNewlines), !nickname.isEmpty { tags.append(["n", nickname]) } if teleported { diff --git a/bitchat/ViewModels/ChatViewModel.swift b/bitchat/ViewModels/ChatViewModel.swift index 41dac351..05872bfc 100644 --- a/bitchat/ViewModels/ChatViewModel.swift +++ b/bitchat/ViewModels/ChatViewModel.swift @@ -897,7 +897,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate { if Date().timeIntervalSince(eventTime) < 15 { return } } if let nickTag = event.tags.first(where: { $0.first == "n" }), nickTag.count >= 2 { - let nick = nickTag[1] + let nick = nickTag[1].trimmingCharacters(in: .whitespacesAndNewlines) self.geoNicknames[event.pubkey.lowercased()] = nick } // Store mapping for geohash sender IDs used in messages (ensures consistent colors) @@ -1616,7 +1616,7 @@ final class ChatViewModel: ObservableObject, BitchatDelegate { } // Cache nickname from tag if present if let nickTag = event.tags.first(where: { $0.first == "n" }), nickTag.count >= 2 { - let nick = nickTag[1] + let nick = nickTag[1].trimmingCharacters(in: .whitespacesAndNewlines) self.geoNicknames[event.pubkey.lowercased()] = nick } // If this pubkey is blocked, skip mapping, participants, and timeline