mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 04:37:44 +00:00
AK: Implement more conforming URL percent encode/decode mechanism
This adds a few new functions to percent encode/decode strings according to the URL specification. The functions allow specifying a PercentEncodeSet, which is defined by the specification. It will be used to replace the current urlencode() and urldecode() functions in a further commit. This commit adds a few duplicate helper functions in the URL class, such as is_digit() and is_ascii_digit(). This will be cleaned up as soon as the upcoming new URL parser will replace the current one.
This commit is contained in:
parent
0e4f7aa8e8
commit
2a6c9bc5f7
2 changed files with 132 additions and 0 deletions
18
AK/URL.h
18
AK/URL.h
|
@ -17,6 +17,18 @@ namespace AK {
|
|||
|
||||
class URL {
|
||||
public:
|
||||
enum class PercentEncodeSet {
|
||||
C0Control,
|
||||
Fragment,
|
||||
Query,
|
||||
SpecialQuery,
|
||||
Path,
|
||||
Userinfo,
|
||||
Component,
|
||||
ApplicationXWWWFormUrlencoded,
|
||||
EncodeURI
|
||||
};
|
||||
|
||||
URL() = default;
|
||||
URL(const StringView&);
|
||||
URL(const char* string)
|
||||
|
@ -67,6 +79,9 @@ public:
|
|||
static bool scheme_requires_port(const StringView&);
|
||||
static u16 default_port_for_scheme(const StringView&);
|
||||
|
||||
static String percent_encode(const StringView& input, PercentEncodeSet set = PercentEncodeSet::Userinfo);
|
||||
static String percent_decode(const StringView& input);
|
||||
|
||||
bool operator==(const URL& other) const
|
||||
{
|
||||
if (this == &other)
|
||||
|
@ -78,6 +93,9 @@ private:
|
|||
bool parse(const StringView&);
|
||||
bool compute_validity() 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);
|
||||
|
||||
bool m_valid { false };
|
||||
u16 m_port { 0 };
|
||||
bool m_data_payload_is_base64 { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue