The valid URL “https://example--example.example.com/” is misjudged as invalid.
Bug Report
📝 Summary
Write a short summary of the bug in here.
- Typia Version: 6.11.1, 7.0.0-dev.20241009-2
💻 Code occuring the bug
import { expect, test } from "vitest";
import {assert, type tags} from "typia";
type A = {
url: string & tags.Format<"url">;
}
test("ex", async () => {
expect(assert<A>({url: "https://example.com/"})).toBeTruthy();
});
test("--", async () => {
expect(assert<A>({url: "https://example--example.example.com/"})).toBeTruthy(); // throws!
});
Use uri instead.
But I would like to state that it is a URL, not a URI. The https://example--example.example.com/ is also valid as a URL.
https://github.com/ajv-validator/ajv-formats/blob/master/src/formats.ts#L63
I'm following the ajv's validation logic.
Need to investigate the such example--example sub-domain is valid.
I think valid because the domains that has double or more hyphen actually exists
- https://hp--community.force.com
- https://lapis--lazuli.booth.pm
- I encountered this!
- https://web.archive.org/web/20220620091215/http://l-------------------------------------------------------------l.tk/
- even the second level, and much hyphens are allowed!
and RFC says only that leading and trailing hyphen is not allowed.
hostname = *[ domainlabel "." ] toplabel
domainlabel = alphadigit | alphadigit *[ alphadigit | "-" ] alphadigit
toplabel = alpha | alpha *[ alphadigit | "-" ] alphadigit
To begin with, the xn--prefix of the internationalized domain is the typical double hyphen. (That is why some domain registrars that use internationalized domains go out of their way to state that they do not tolerate double hyphens in the third and fourth characters.)