Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion scripts/getLatestTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const { unicodeVersion } = require("../package.json");

const pipelinePromise = promisify(pipeline);

// Update this by going to https://github.com/web-platform-tests/wpt/tree/master/url/resources and pressing "y" on the
// keyboard.
const wptSHA = "417a64d8351792b768efe089934edce3259f63d1";

main().catch(e => {
console.error(e);
process.exit(1);
Expand All @@ -28,7 +32,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/${wptSHA}/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/${wptSHA}/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