Skip to content

Fix empty label handling #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ function validateLabel(label, { checkHyphens, checkBidi, checkJoiners, processin
}

// https://tools.ietf.org/html/rfc5893#section-2
if (checkBidi) {
// For the codePoints length check, see discussion in https://github.com/jsdom/whatwg-url/pull/250 and the second item
// in https://github.com/whatwg/url/issues/744.
if (checkBidi && codePoints.length > 0) {
let rtl;

// 1
Expand Down
7 changes: 6 additions & 1 deletion scripts/getLatestTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ async function main() {
})(),
(async () => {
const asciiTarget = fs.createWriteStream(path.resolve(__dirname, "../test/fixtures/toascii.json"));
const response = await fetch("https://github.com/web-platform-tests/wpt/raw/112ad5ca55d55f6da2ccc7468e6dcc91b4e5d223/url/resources/toascii.json");
const response = await fetch("https://github.com/web-platform-tests/wpt/raw/7234ceaeb1505c42bef05a88a77da930653a4e31/url/resources/toascii.json");
await pipelinePromise(response.body, asciiTarget);
})(),
(async () => {
const asciiTarget = fs.createWriteStream(path.resolve(__dirname, "../test/fixtures/IdnaTestV2ToASCII.json"));
const response = await fetch("https://github.com/web-platform-tests/wpt/raw/7234ceaeb1505c42bef05a88a77da930653a4e31/url/resources/IdnaTestV2.json");
await pipelinePromise(response.body, asciiTarget);
})()
]);
Expand Down
25 changes: 24 additions & 1 deletion test/toascii.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const assert = require("assert");
const tr46 = require("../index.js");

const toASCIITestCases = require("./fixtures/toascii.json");
const idnaTestV2 = require("./fixtures/IdnaTestV2ToASCII.json");

function testToASCII(testCase) {
return () => {
Expand All @@ -29,7 +30,29 @@ describe("ToASCII", () => {

let description = testCase.input;
if (testCase.comment) {
description = ` (${testCase.comment})`;
description += ` (${testCase.comment})`;
}

specify(description, testToASCII(testCase));
}
});

describe("ToASCII via IdnaTestV2.json in wpt", () => {
for (const testCase of idnaTestV2) {
if (typeof testCase === "string") {
// It's a "comment"; skip it.
continue;
}

if (testCase.input.includes("?")) {
// ToASCII will not fail on these. But, the URL Standard will. IdnaTestV2.json is mostly focused on the URL
// Standard, so it expects failures. We should skip them.
continue;
}

let description = testCase.input;
if (testCase.comment) {
description += ` (${testCase.comment})`;
}

specify(description, testToASCII(testCase));
Expand Down