mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 16:19:23 +00:00
LibURL: Add 'about:XXX' helper factory functions
Currently we create URLs such as 'about:blank' through the StringView or ByteString constructor of URL. However, in order to elimate the use of URL::is_valid, we need to get rid of these constructors as it makes it way too easy to create an invalid URL. It is very cumbersome to construct an 'about:blank' URL when using URL::Parser::basic_parse. So instead of doing that, create some helper functions which will create the 'about:XXX' URLs with the correct properties set. Conveniently, this is also a much faster way of creating these URLs as it means we do not need to parse the URL and can set all of the members up front.
This commit is contained in:
parent
53826995f6
commit
07f054e067
Notes:
github-actions[bot]
2025-02-15 17:07:05 +00:00
Author: https://github.com/shannonbooth
Commit: 07f054e067
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3586
Reviewed-by: https://github.com/tcl3 ✅
2 changed files with 18 additions and 0 deletions
|
@ -475,6 +475,16 @@ String percent_encode(StringView input, PercentEncodeSet set, SpaceAsPlus space_
|
|||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
URL URL::about(String path)
|
||||
{
|
||||
URL url;
|
||||
url.m_data->valid = true;
|
||||
url.m_data->scheme = "about"_string;
|
||||
url.m_data->paths = { move(path) };
|
||||
url.m_data->cannot_be_a_base_url = true;
|
||||
return url;
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#percent-decode
|
||||
ByteString percent_decode(StringView input)
|
||||
{
|
||||
|
|
|
@ -147,6 +147,8 @@ public:
|
|||
Optional<BlobURLEntry> const& blob_url_entry() const { return m_data->blob_url_entry; }
|
||||
void set_blob_url_entry(Optional<BlobURLEntry> entry) { m_data->blob_url_entry = move(entry); }
|
||||
|
||||
static URL about(String path);
|
||||
|
||||
private:
|
||||
bool compute_validity() const;
|
||||
|
||||
|
@ -211,6 +213,12 @@ URL create_with_data(StringView mime_type, StringView payload, bool is_base64 =
|
|||
bool is_public_suffix(StringView host);
|
||||
Optional<String> get_public_suffix(StringView host);
|
||||
|
||||
inline URL about_blank() { return URL::about("blank"_string); }
|
||||
inline URL about_srcdoc() { return URL::about("srcdoc"_string); }
|
||||
inline URL about_error() { return URL::about("error"_string); }
|
||||
inline URL about_version() { return URL::about("version"_string); }
|
||||
inline URL about_newtab() { return URL::about("newtab"_string); }
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue