1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:17:35 +00:00

AK: Add spec-compliant URL serialization methods

This adds URL serialization methods which are more in line with the
specification.

The serialize_for_display() method should be used e.g. in the browser
address bar, and as per the spec should not display username and
password. Furthermore, it could decode most percent-encoded code points,
although that is not implemented yet.
This commit is contained in:
Max Wipfli 2021-05-25 22:32:39 +02:00 committed by Andreas Kling
parent 0d0ed4962f
commit 1697f3c35b
2 changed files with 131 additions and 0 deletions

View file

@ -30,6 +30,11 @@ public:
EncodeURI
};
enum class ExcludeFragment {
No,
Yes
};
URL() = default;
URL(const StringView&);
URL(const char* string)
@ -78,6 +83,9 @@ public:
return percent_encode(to_string(), PercentEncodeSet::EncodeURI);
}
String serialize(ExcludeFragment = ExcludeFragment::No) const;
String serialize_for_display() const;
URL complete_url(const String&) const;
bool data_payload_is_base64() const { return m_data_payload_is_base64; }
@ -115,6 +123,7 @@ private:
bool parse(const StringView&);
bool compute_validity() const;
String serialize_data_url() const;
static void append_percent_encoded_if_necessary(StringBuilder&, u32 code_point, PercentEncodeSet set = PercentEncodeSet::Userinfo);
static void append_percent_encoded(StringBuilder&, u32 code_point);