mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 08:24:58 +00:00
AK+Everywhere: Add ApplyPercentDecoding option to URL getters
The defaults selected for this are based on the behaviour of URL when it applied percent decoding during parsing. This does mean now in some cases the getters will allocate, but percent_decode() checks if there's anything to decode first, so in many cases still won't.
This commit is contained in:
parent
b9e03071cc
commit
5acd40c525
3 changed files with 43 additions and 18 deletions
39
AK/URL.cpp
39
AK/URL.cpp
|
@ -47,6 +47,36 @@ URL URL::complete_url(StringView relative_url) const
|
|||
return URLParser::parse(relative_url, *this);
|
||||
}
|
||||
|
||||
DeprecatedString URL::username(ApplyPercentDecoding apply_percent_decoding) const
|
||||
{
|
||||
return apply_percent_decoding == ApplyPercentDecoding::Yes ? percent_decode(m_username) : m_username;
|
||||
}
|
||||
|
||||
DeprecatedString URL::password(ApplyPercentDecoding apply_percent_decoding) const
|
||||
{
|
||||
return apply_percent_decoding == ApplyPercentDecoding::Yes ? percent_decode(m_password) : m_password;
|
||||
}
|
||||
|
||||
DeprecatedString URL::basename(ApplyPercentDecoding apply_percent_decoding) const
|
||||
{
|
||||
if (!m_valid)
|
||||
return {};
|
||||
if (m_paths.is_empty())
|
||||
return {};
|
||||
auto& last_segment = m_paths.last();
|
||||
return apply_percent_decoding == ApplyPercentDecoding::Yes ? percent_decode(last_segment) : last_segment;
|
||||
}
|
||||
|
||||
DeprecatedString URL::query(ApplyPercentDecoding apply_percent_decoding) const
|
||||
{
|
||||
return apply_percent_decoding == ApplyPercentDecoding::Yes ? percent_decode(m_query) : m_query;
|
||||
}
|
||||
|
||||
DeprecatedString URL::fragment(ApplyPercentDecoding apply_percent_decoding) const
|
||||
{
|
||||
return apply_percent_decoding == ApplyPercentDecoding::Yes ? percent_decode(m_fragment) : m_fragment;
|
||||
}
|
||||
|
||||
// NOTE: This only exists for compatibility with the existing URL tests which check for both .is_null() and .is_empty().
|
||||
static DeprecatedString deprecated_string_percent_encode(DeprecatedString const& input, URL::PercentEncodeSet set = URL::PercentEncodeSet::Userinfo, URL::SpaceAsPlus space_as_plus = URL::SpaceAsPlus::No)
|
||||
{
|
||||
|
@ -389,15 +419,6 @@ bool URL::equals(URL const& other, ExcludeFragment exclude_fragments) const
|
|||
return serialize(exclude_fragments) == other.serialize(exclude_fragments);
|
||||
}
|
||||
|
||||
DeprecatedString URL::basename() const
|
||||
{
|
||||
if (!m_valid)
|
||||
return {};
|
||||
if (m_paths.is_empty())
|
||||
return {};
|
||||
return m_paths.last();
|
||||
}
|
||||
|
||||
void URL::append_percent_encoded(StringBuilder& builder, u32 code_point)
|
||||
{
|
||||
if (code_point <= 0x7f)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue