Allow dot in usernames per NIP-05 local-part spec

Extend usernameRE to [a-z0-9_.-], preserve dots in SanitizeForUsername,
and add tests for validation, sanitization, and nip05 sync precedence.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-05 06:10:14 +00:00
parent 7a1ceb49c3
commit bbfc64733a
4 changed files with 19 additions and 6 deletions

View File

@@ -17,6 +17,10 @@ func TestSanitizeForUsername(t *testing.T) {
{"alice_", "alice"},
{"alice--bob", "alice-bob"},
{"alice__bob", "alice_bob"},
{"alice.bob", "alice.bob"},
{"alice..bob", "alice.bob"},
{".alice", "alice"},
{"alice.", "alice"},
{" ", ""},
{"", ""},
{"!!!", ""},
@@ -59,6 +63,11 @@ func TestCandidateFromMetadataPrecedence(t *testing.T) {
name: "alice", nip05: "preferred@azzamo.net", dom: domain,
want: "preferred",
},
{
desc: "nip05 local part with dot is preserved",
name: "alice", nip05: "alice.smith@azzamo.net", dom: domain,
want: "alice.smith",
},
{
desc: "nip05 ignored when domain differs",
name: "alice", nip05: "preferred@other.example", dom: domain,