From bfdb25b87bd4946f00d290ec170873b030e620d4 Mon Sep 17 00:00:00 2001 From: Vaibhav mittal Date: Fri, 13 Mar 2026 10:13:51 +0000 Subject: [PATCH 1/2] fix(format): use RFC1123 hostname validator for legacy drafts Signed-off-by: Vaibhav mittal --- formats/handlers/draft-04/hostname.js | 4 +- formats/hostname.spec.ts | 56 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 formats/hostname.spec.ts diff --git a/formats/handlers/draft-04/hostname.js b/formats/handlers/draft-04/hostname.js index 02344e4f..b5b52870 100644 --- a/formats/handlers/draft-04/hostname.js +++ b/formats/handlers/draft-04/hostname.js @@ -1,7 +1,7 @@ -import { isAsciiIdn } from "@hyperjump/json-schema-formats"; +import { isHostname } from "@hyperjump/json-schema-formats"; export default { id: "https://json-schema.org/format/draft-04/hostname", - handler: (hostname) => typeof hostname !== "string" || isAsciiIdn(hostname) + handler: (hostname) => typeof hostname !== "string" || isHostname(hostname) }; diff --git a/formats/hostname.spec.ts b/formats/hostname.spec.ts new file mode 100644 index 00000000..6eae70c5 --- /dev/null +++ b/formats/hostname.spec.ts @@ -0,0 +1,56 @@ +import { describe, it, expect, beforeAll, afterAll } from "vitest"; +import { registerSchema, unregisterSchema, validate } from "../lib/index.js"; +import "./index.js"; +import "../draft-06/index.js"; +import "../draft-04/index.js"; + +import type { Validator } from "../lib/index.js"; + + +describe("hostname", () => { + describe("draft4", () => { + const schemaUri = "https://json-schema.org/tests/draft4/hostname"; + let _validate: Validator; + + beforeAll(async () => { + registerSchema({ + type: "string", + format: "hostname" + }, schemaUri, "http://json-schema.org/draft-04/schema"); + + _validate = await validate(schemaUri); + }); + + afterAll(() => { + unregisterSchema(schemaUri); + }); + + it("accepts rfc1123 hostname labels with consecutive hyphens", () => { + const output = _validate("ab--cd.example"); + expect(output.valid).to.equal(true); + }); + }); + + describe("draft6", () => { + const schemaUri = "https://json-schema.org/tests/draft6/hostname"; + let _validate: Validator; + + beforeAll(async () => { + registerSchema({ + type: "string", + format: "hostname" + }, schemaUri, "http://json-schema.org/draft-06/schema"); + + _validate = await validate(schemaUri); + }); + + afterAll(() => { + unregisterSchema(schemaUri); + }); + + it("accepts rfc1123 hostname labels with consecutive hyphens", () => { + const output = _validate("ab--cd.example"); + expect(output.valid).to.equal(true); + }); + }); +}); From a399204c74855c4264e04b8f5758a06e5287001b Mon Sep 17 00:00:00 2001 From: Vaibhav mittal Date: Fri, 13 Mar 2026 19:53:52 +0000 Subject: [PATCH 2/2] test: remove regression test per maintainer request Signed-off-by: Vaibhav mittal --- formats/hostname.spec.ts | 56 ---------------------------------------- 1 file changed, 56 deletions(-) delete mode 100644 formats/hostname.spec.ts diff --git a/formats/hostname.spec.ts b/formats/hostname.spec.ts deleted file mode 100644 index 6eae70c5..00000000 --- a/formats/hostname.spec.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { describe, it, expect, beforeAll, afterAll } from "vitest"; -import { registerSchema, unregisterSchema, validate } from "../lib/index.js"; -import "./index.js"; -import "../draft-06/index.js"; -import "../draft-04/index.js"; - -import type { Validator } from "../lib/index.js"; - - -describe("hostname", () => { - describe("draft4", () => { - const schemaUri = "https://json-schema.org/tests/draft4/hostname"; - let _validate: Validator; - - beforeAll(async () => { - registerSchema({ - type: "string", - format: "hostname" - }, schemaUri, "http://json-schema.org/draft-04/schema"); - - _validate = await validate(schemaUri); - }); - - afterAll(() => { - unregisterSchema(schemaUri); - }); - - it("accepts rfc1123 hostname labels with consecutive hyphens", () => { - const output = _validate("ab--cd.example"); - expect(output.valid).to.equal(true); - }); - }); - - describe("draft6", () => { - const schemaUri = "https://json-schema.org/tests/draft6/hostname"; - let _validate: Validator; - - beforeAll(async () => { - registerSchema({ - type: "string", - format: "hostname" - }, schemaUri, "http://json-schema.org/draft-06/schema"); - - _validate = await validate(schemaUri); - }); - - afterAll(() => { - unregisterSchema(schemaUri); - }); - - it("accepts rfc1123 hostname labels with consecutive hyphens", () => { - const output = _validate("ab--cd.example"); - expect(output.valid).to.equal(true); - }); - }); -});