fix(api): 🔒 Replace bad webfinger regex with good one

This commit is contained in:
Jesse Wierzbinski 2024-05-12 16:27:40 -10:00
parent 9ad0f88ff2
commit 4f070c9b65
No known key found for this signature in database
3 changed files with 33 additions and 16 deletions

View file

@ -11,7 +11,9 @@ import {
createRegExp,
digit,
exactly,
global,
letter,
maybe,
oneOrMore,
} from "magic-regexp";
import { parse } from "qs";
@ -64,6 +66,28 @@ export const emojiValidatorWithColons = createRegExp(
[caseInsensitive],
);
export const mentionValidator = createRegExp(
exactly("@"),
oneOrMore(anyOf(letter.lowercase, digit, charIn("-"))).groupedAs(
"username",
),
maybe(
exactly("@"),
oneOrMore(anyOf(letter, digit, charIn("_-.:"))).groupedAs("domain"),
),
[global],
);
export const webfingerMention = createRegExp(
exactly("acct:"),
oneOrMore(anyOf(letter, digit, charIn("-"))).groupedAs("username"),
maybe(
exactly("@"),
oneOrMore(anyOf(letter, digit, charIn("_-.:"))).groupedAs("domain"),
),
[],
);
export const handleZodError = (
result:
| { success: true; data?: object }