diff --git a/src/lib/__tests__/account-id-port.test.ts b/src/lib/__tests__/account-id-port.test.ts index 18a826a6..56bd0384 100644 --- a/src/lib/__tests__/account-id-port.test.ts +++ b/src/lib/__tests__/account-id-port.test.ts @@ -49,6 +49,14 @@ describe('generateAccountId', () => { }); }); +describe('registry entries without a server', () => { + it('are skipped instead of throwing', () => { + setKnownAccounts([{ id: 'u@example.org@mail.example.org', username: 'u@example.org' } as never]); + expect(generateAccountId('u@example.org', 'https://mail.example.org')).toBe('u@example.org@mail.example.org'); + expect(generateAccountId('u@example.org', 'https://mail.example.org:8443')).toBe('u@example.org@mail.example.org:8443'); + }); +}); + describe('a new default-port account next to a kept host-only id', () => { const legacy = { id: 'u@example.org@mail.example.org', username: 'u@example.org', serverUrl: 'https://mail.example.org:8120' }; diff --git a/src/lib/account-utils.ts b/src/lib/account-utils.ts index f60eb6e3..1a445bf5 100644 --- a/src/lib/account-utils.ts +++ b/src/lib/account-utils.ts @@ -96,11 +96,13 @@ export function generateAccountId(username: string, serverUrl: string): string { if (id === legacy) { const explicit = `${id}:${defaultPortOf(serverUrl)}`; if (knownAccounts.some((a) => a.id === explicit)) return explicit; - const taken = knownAccounts.some((a) => a.id === id && `${a.username}@${serverHostLabel(a.serverUrl)}` !== id); + const taken = knownAccounts.some((a) => a.id === id && !!a.serverUrl + && `${a.username}@${serverHostLabel(a.serverUrl)}` !== id); return taken ? explicit : id; } const kept = knownAccounts.find((a) => a.id === legacy && a.username === username + && !!a.serverUrl && `${a.username}@${serverHostLabel(a.serverUrl)}` === id); return kept ? kept.id : id; }