From 28aa4ca767d07a578633aa8a3d8cdff1586e00cc Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 9 Aug 2023 17:23:23 +0100 Subject: [PATCH] AK: Add URL::raw_fragment() This is a little hackish. Part of the algorithm to get the indicated part of a DOM::Document https://html.spec.whatwg.org/multipage/browsing-the-web.html#the-indicated-part-of-the-document wants to first get the URL's fragment, use it, and then later percent-decode it and use that. So, we need a way to get that un-decoded fragment. --- AK/URL.cpp | 5 +++++ AK/URL.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/AK/URL.cpp b/AK/URL.cpp index 64f89e74796..8ecf1313d54 100644 --- a/AK/URL.cpp +++ b/AK/URL.cpp @@ -72,6 +72,11 @@ DeprecatedString URL::fragment() const return percent_decode(m_fragment); } +DeprecatedString URL::raw_fragment() const +{ + return 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) { diff --git a/AK/URL.h b/AK/URL.h index de47383990d..bf7a6364756 100644 --- a/AK/URL.h +++ b/AK/URL.h @@ -83,7 +83,9 @@ public: ErrorOr serialized_host() const; DeprecatedString basename() const; DeprecatedString query() const; + // NOTE: fragment() is percent-decoded, raw_fragment() is not. DeprecatedString fragment() const; + DeprecatedString raw_fragment() const; Optional port() const { return m_port; } DeprecatedString path_segment_at_index(size_t index) const; size_t path_segment_count() const { return m_paths.size(); }