mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
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:
parent
25153703c9
commit
4fdd4dd979
3 changed files with 43 additions and 4 deletions
15
AK/URL.cpp
15
AK/URL.cpp
|
@ -204,22 +204,29 @@ bool URL::compute_validity() const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://url.spec.whatwg.org/#default-port
|
||||||
u16 URL::default_port_for_scheme(StringView scheme)
|
u16 URL::default_port_for_scheme(StringView scheme)
|
||||||
{
|
{
|
||||||
|
// Spec defined mappings with port:
|
||||||
|
if (scheme == "ftp")
|
||||||
|
return 21;
|
||||||
if (scheme == "http")
|
if (scheme == "http")
|
||||||
return 80;
|
return 80;
|
||||||
if (scheme == "https")
|
if (scheme == "https")
|
||||||
return 443;
|
return 443;
|
||||||
|
if (scheme == "ws")
|
||||||
|
return 80;
|
||||||
|
if (scheme == "wss")
|
||||||
|
return 443;
|
||||||
|
|
||||||
|
// NOTE: not in spec, but we support these too
|
||||||
if (scheme == "gemini")
|
if (scheme == "gemini")
|
||||||
return 1965;
|
return 1965;
|
||||||
if (scheme == "irc")
|
if (scheme == "irc")
|
||||||
return 6667;
|
return 6667;
|
||||||
if (scheme == "ircs")
|
if (scheme == "ircs")
|
||||||
return 6697;
|
return 6697;
|
||||||
if (scheme == "ws")
|
|
||||||
return 80;
|
|
||||||
if (scheme == "wss")
|
|
||||||
return 443;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
9
Tests/LibWeb/Text/expected/URL/url.txt
Normal file
9
Tests/LibWeb/Text/expected/URL/url.txt
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
ftp://serenityos.org:21
|
||||||
|
protocol => 'ftp:'
|
||||||
|
username => ''
|
||||||
|
password => ''
|
||||||
|
host => 'serenityos.org'
|
||||||
|
hostname => 'serenityos.org'
|
||||||
|
port => ''
|
||||||
|
pathname => '/'
|
||||||
|
search => ''
|
23
Tests/LibWeb/Text/input/URL/url.html
Normal file
23
Tests/LibWeb/Text/input/URL/url.html
Normal 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>
|
Loading…
Add table
Add a link
Reference in a new issue