1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 13:55:00 +00:00
serenity/Tests/LibWeb/Text/input/URL/url.html
Shannon Booth 453dd0cf44 AK: Properly implement steps for shortening a URLs path
Instead of implementing this inline, put it into a function. Use this
new function to correctly implement shortening paths for some places
where this logic was previously missing.

Before these changes, the pathname for the included test was incorrectly
being set to '/' as we were not considering the windows drive letter.
2023-10-26 11:11:41 +02:00

35 lines
1.3 KiB
HTML

<script src="../include.js"></script>
<script>
test(() => {
function printURL(input, base) {
if (base === undefined)
println(`new URL('${input}', ${base})`);
else
println(`new URL('${input}', '${base}')`);
const url = new URL(input, base);
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}'`);
}
for (url of [
{ 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' },
]) {
printURL(url.input, url.base);
}
});
</script>