Files
ladybird/Tests/LibWeb/Text/input/URL/url.html
Shannon Booth 9b6a1de777 LibWeb: Implement URL.parse
This was an addition to the URL spec, see:

https://github.com/whatwg/url/commit/58acb0
2024-05-13 09:21:12 +02:00

48 lines
1.6 KiB
HTML

<script src="../include.js"></script>
<script>
test(() => {
function printURL(url) {
println(`protocol => '${url.protocol}'`);
println(`username => '${url.username}'`);
println(`password => '${url.password}'`);
println(`host => '${url.host}'`);
println(`hostname => '${url.hostname}'`);
println(`port => '${url.port}'`);
println(`pathname => '${url.pathname}'`);
println(`search => '${url.search}'`);
println(`hash => '${url.hash}'`);
}
const urls = [
{ input: 'ftp://serenityos.org:21' },
{ input: 'http://[0:1:0:1:0:1:0:1]' },
{ input: 'http://[1:0:1:0:1:0:1:0]' },
{ input: 'http://[1:1:0:0:1:0:0:0]/' },
{ input: 'unknown://serenityos.org:0' },
{ input: 'http://serenityos.org/cat?dog#meow"woof' },
{ input: '/hello', base: 'file://friends/' },
{ input: '//d:/..', base: 'file:///C:/a/b' },
];
for (url of urls) {
if (url.base === undefined)
println(`new URL('${url.input}', ${url.base})`);
else
println(`new URL('${url.input}', '${url.base}')`);
printURL(new URL(url.input, url.base));
}
println('=========================================');
for (url of urls) {
if (url.base === undefined)
println(`URL.parse('${url.input}', ${url.base})`);
else
println(`URL.parse('${url.input}', '${url.base}')`);
printURL(URL.parse(url.input, url.base));
}
});
</script>