mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
AK: Add hostname parameter to URL::create_with_file_scheme()
This adds a hostname parameter as the third parameter to URL::create_with_file_scheme(). If the hostname is "localhost", it will be ignored (as per the URL specification). This can for example be used by ls(1) to create more conforming file URLs.
This commit is contained in:
parent
ce80188d6f
commit
5caaa52bee
Notes:
sideshowbarker
2024-07-18 17:03:42 +09:00
Author: https://github.com/MaxWipfli Commit: https://github.com/SerenityOS/serenity/commit/5caaa52bee1 Pull-request: https://github.com/SerenityOS/serenity/pull/7478 Reviewed-by: https://github.com/awesomekling
2 changed files with 6 additions and 3 deletions
|
@ -178,14 +178,17 @@ u16 URL::default_port_for_scheme(const StringView& scheme)
|
|||
return 0;
|
||||
}
|
||||
|
||||
URL URL::create_with_file_scheme(const String& path, const String& fragment)
|
||||
URL URL::create_with_file_scheme(const String& path, const String& fragment, const String& hostname)
|
||||
{
|
||||
LexicalPath lexical_path(path);
|
||||
if (!lexical_path.is_valid() || !lexical_path.is_absolute())
|
||||
return {};
|
||||
|
||||
URL url;
|
||||
url.set_scheme("file");
|
||||
url.set_host(String::empty());
|
||||
// NOTE: If the hostname is localhost (or null, which implies localhost), it should be set to the empty string.
|
||||
// This is because a file URL always needs a non-null hostname.
|
||||
url.set_host(hostname.is_null() || hostname == "localhost" ? String::empty() : hostname);
|
||||
url.set_paths(lexical_path.parts());
|
||||
// NOTE: To indicate that we want to end the path with a slash, we have to append an empty path segment.
|
||||
if (path.ends_with('/'))
|
||||
|
|
2
AK/URL.h
2
AK/URL.h
|
@ -92,7 +92,7 @@ public:
|
|||
const String& data_payload() const { return m_data_payload; }
|
||||
|
||||
static URL create_with_url_or_path(const String&);
|
||||
static URL create_with_file_scheme(const String& path, const String& fragment = {});
|
||||
static URL create_with_file_scheme(const String& path, const String& fragment = {}, const String& hostname = {});
|
||||
static URL create_with_file_protocol(const String& path, const String& fragment = {}) { return create_with_file_scheme(path, fragment); }
|
||||
static URL create_with_data(const StringView& mime_type, const StringView& payload, bool is_base64 = false);
|
||||
|
||||
|
|
Loading…
Reference in a new issue