Allow international URLs to pass validation (#1717)

This commit is contained in:
Micah Stairs 2025-06-26 13:16:42 -04:00 committed by GitHub
parent 1919799bed
commit 9a5d40c3cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 66 additions and 61 deletions

View File

@ -76,4 +76,9 @@ describe("URL Schema Validation", () => {
it("should reject malformed URLs containing multiple 'http://'", () => { it("should reject malformed URLs containing multiple 'http://'", () => {
expect(() => url.parse("http://ex ample.com/")).toThrow("Invalid URL"); expect(() => url.parse("http://ex ample.com/")).toThrow("Invalid URL");
}); });
it("should accept URLs with international domain names", () => {
expect(() => url.parse("http://xn--1lqv92a901a.xn--ses554g/")).not.toThrow();
});
}); });

View File

@ -61,7 +61,7 @@ export const url = z.preprocess(
.regex(/^https?:\/\//, "URL uses unsupported protocol") .regex(/^https?:\/\//, "URL uses unsupported protocol")
.refine( .refine(
(x) => (x) =>
/\.[a-zA-Z\u0400-\u04FF\u0500-\u052F\u2DE0-\u2DFF\uA640-\uA69F]{2,}(:\d+)?([\/?#]|$)/i.test( /\.[a-zA-Z0-9-\u0400-\u04FF\u0500-\u052F\u2DE0-\u2DFF\uA640-\uA69F]{2,}(:\d+)?([\/?#]|$)/i.test(
x, x,
), ),
"URL must have a valid top-level domain or be a valid path", "URL must have a valid top-level domain or be a valid path",