typia icon indicating copy to clipboard operation
typia copied to clipboard

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

Open Narazaka opened this issue 1 year ago • 5 comments

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!
});

Narazaka avatar Oct 08 '24 17:10 Narazaka

Use uri instead.

samchon avatar Oct 08 '24 18:10 samchon

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.

Narazaka avatar Oct 08 '24 18:10 Narazaka

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.

samchon avatar Oct 08 '24 18:10 samchon

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

Narazaka avatar Oct 09 '24 06:10 Narazaka

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

Narazaka avatar Oct 09 '24 06:10 Narazaka