mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +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
Notes:
sideshowbarker
2024-07-17 18:06:52 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/4fdd4dd979 Pull-request: https://github.com/SerenityOS/serenity/pull/20278
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;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
|
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…
Reference in a new issue