Skip to content

Instantly share code, notes, and snippets.

@domenic
Created December 30, 2022 09:53
Show Gist options
  • Save domenic/77f4db1f2b6cf678d9da6e5685e3155c to your computer and use it in GitHub Desktop.
Save domenic/77f4db1f2b6cf678d9da6e5685e3155c to your computer and use it in GitHub Desktop.
urltestdata.json generator using jsdom/whatwg-url
"use strict";
const { URL } = require(".");
const inputs = [
"https://\u0000y",
"https://x/\u0000y",
"https://x/?\u0000y",
"https://x/?#\u0000y"
];
for (const input of inputs.slice()) {
inputs.push(input.replaceAll("\u0000", "\u{FFFF}"));
}
for (const input of inputs.slice()) {
inputs.push(input.replaceAll("https://", "non-special:"));
}
const outputs = [];
for (const input of inputs) {
try {
const u = new URL(input, "about:blank");
outputs.push({
input,
base: "about:blank",
hash: u.hash,
host: u.host,
hostname: u.hostname,
href: u.href,
password: u.password,
pathname: u.pathname,
port: u.port,
protocol: u.protocol,
search: u.search,
username: u.username
});
} catch {
outputs.push({
input,
base: "about:blank",
failure: true
});
}
}
console.log(JSON.stringify(outputs, 0, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment