From 4fdd4dd979a9f5cba9d6840f425f0549a0897b33 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Mon, 31 Jul 2023 20:23:53 +1200 Subject: [PATCH] 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. --- AK/URL.cpp | 15 +++++++++++---- Tests/LibWeb/Text/expected/URL/url.txt | 9 +++++++++ Tests/LibWeb/Text/input/URL/url.html | 23 +++++++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/URL/url.txt create mode 100644 Tests/LibWeb/Text/input/URL/url.html diff --git a/AK/URL.cpp b/AK/URL.cpp index eb7da264d1..06e21ae4b2 100644 --- a/AK/URL.cpp +++ b/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; } diff --git a/Tests/LibWeb/Text/expected/URL/url.txt b/Tests/LibWeb/Text/expected/URL/url.txt new file mode 100644 index 0000000000..ae26759dc9 --- /dev/null +++ b/Tests/LibWeb/Text/expected/URL/url.txt @@ -0,0 +1,9 @@ +ftp://serenityos.org:21 +protocol => 'ftp:' +username => '' +password => '' +host => 'serenityos.org' +hostname => 'serenityos.org' +port => '' +pathname => '/' +search => '' diff --git a/Tests/LibWeb/Text/input/URL/url.html b/Tests/LibWeb/Text/input/URL/url.html new file mode 100644 index 0000000000..c37a2ef030 --- /dev/null +++ b/Tests/LibWeb/Text/input/URL/url.html @@ -0,0 +1,23 @@ + +