fix(jmap): use path extraction instead of origin-length slicing for URL rewrite

When Stalwart returns session URLs with explicit :443 port, the URL
parser normalizes it out but the original string keeps it, causing
string slicing to produce wrong offsets. Now extracts the path by
finding the first / after // instead of relying on origin length.
This commit is contained in:
Matthieu MALVACHE
2026-02-25 12:44:41 +01:00
parent 602d50b703
commit 8843b70add
+5 -4
View File
@@ -212,10 +212,11 @@ export class JMAPClient {
private rewriteSessionUrl(url: string): string {
try {
const urlOrigin = new URL(url).origin;
const serverOrigin = new URL(this.serverUrl).origin;
if (urlOrigin === serverOrigin) return url;
return serverOrigin + url.slice(urlOrigin.length);
const parsed = new URL(url);
const server = new URL(this.serverUrl);
if (parsed.origin === server.origin) return url;
const pathAndRest = url.slice(url.indexOf('/', url.indexOf('//') + 2));
return server.origin + pathAndRest;
} catch {
return url;
}