AK: Add missing default port definitions for FTP scheme URLs

This is defined in the spec, but was missing in our table. Fix this, and
add a spec comment for what is missing. Also begin a basic text based
test for URL, so we can get some coverage of LibWeb's usage of URL too.
This commit is contained in:
Shannon Booth 2023-07-31 20:23:53 +12:00 committed by Andreas Kling
parent 25153703c9
commit 4fdd4dd979
Notes: sideshowbarker 2024-07-17 18:06:52 +09:00
3 changed files with 43 additions and 4 deletions

View file

@ -204,22 +204,29 @@ bool URL::compute_validity() const
return true;
}
// https://url.spec.whatwg.org/#default-port
u16 URL::default_port_for_scheme(StringView scheme)
{
// Spec defined mappings with port:
if (scheme == "ftp")
return 21;
if (scheme == "http")
return 80;
if (scheme == "https")
return 443;
if (scheme == "ws")
return 80;
if (scheme == "wss")
return 443;
// NOTE: not in spec, but we support these too
if (scheme == "gemini")
return 1965;
if (scheme == "irc")
return 6667;
if (scheme == "ircs")
return 6697;
if (scheme == "ws")
return 80;
if (scheme == "wss")
return 443;
return 0;
}

View file

@ -0,0 +1,9 @@
ftp://serenityos.org:21
protocol => 'ftp:'
username => ''
password => ''
host => 'serenityos.org'
hostname => 'serenityos.org'
port => ''
pathname => '/'
search => ''

View file

@ -0,0 +1,23 @@
<script src="../include.js"></script>
<script>
test(() => {
function printURL(input) {
println(input);
const url = new URL(input);
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}'`);
}
for (url of [
'ftp://serenityos.org:21',
]) {
printURL(url);
}
});
</script>