fix: skip saved accounts without a server when picking an account id

This commit is contained in:
Linus Rath
2026-10-31 15:51:50 +01:00
parent ff01246c92
commit b43472dda4
2 changed files with 11 additions and 1 deletions
@@ -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' };
+3 -1
View File
@@ -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;
}