Created
December 30, 2022 09:53
-
-
Save domenic/77f4db1f2b6cf678d9da6e5685e3155c to your computer and use it in GitHub Desktop.
urltestdata.json generator using jsdom/whatwg-url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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