pathnameのルートが@で始まるときだけacct like urlとする

This commit is contained in:
tamaina 2025-08-30 17:22:22 +09:00
parent 289051b314
commit a3ed7d994b
1 changed files with 4 additions and 2 deletions

View File

@ -33,6 +33,9 @@ export class UrlIsNotAcctLikeError extends Error {
} }
} }
/**
* Only supports `https?://example.com/@username` or `https?://example.com/@username@other.example.com`
*/
export function parseUrl(str: string): Acct { export function parseUrl(str: string): Acct {
const url = new URL(str); const url = new URL(str);
@ -40,8 +43,7 @@ export function parseUrl(str: string): Acct {
if (url.search.length > 0) throw new UrlIsNotAcctLikeError(); if (url.search.length > 0) throw new UrlIsNotAcctLikeError();
const splited = url.pathname.split('/'); const splited = url.pathname.split('/');
let path = splited.pop(); const path = splited[1];
if (path === '') path = splited.pop(); // If the last segment is empty due to a trailing '/', use the previous segment
if (!path) throw new UrlIsNotAcctLikeError(); if (!path) throw new UrlIsNotAcctLikeError();
if (!path.startsWith('@')) throw new UrlIsNotAcctLikeError(); if (!path.startsWith('@')) throw new UrlIsNotAcctLikeError();