samchon / typia

Super-fast/easy runtime validators and serializers via transformation
https://typia.io/
MIT License
4.55k stars 157 forks source link

The valid URL “https://example--example.example.com/” is misjudged as invalid. #1315

Open Narazaka opened 1 week ago

Narazaka commented 1 week ago

Bug Report

📝 Summary

Write a short summary of the bug in here.

💻 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!
});
samchon commented 1 week ago

Use uri instead.

Narazaka commented 1 week ago

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.

samchon commented 1 week ago

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.

Narazaka commented 1 week ago

I think valid because the domains that has double or more hyphen actually exists

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
Narazaka commented 1 week ago

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.)