mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 12:05:15 +00:00
AK: Implement URL::serialize_path()
to spec
This commit also reverts db5ad0c
since code outside of the web spec
expects serialized paths to be percent decoded.
Also, there are issues trying to implement the concept "opaque
path". For now, we still use the old cannot_be_a_base_url(), but its
usage needs to be removed in favor of a has_opaque_path() as the spec
has changed since then.
This commit is contained in:
parent
a2810d3cf8
commit
b6b4e59bf7
Notes:
sideshowbarker
2024-07-17 01:11:48 +09:00
Author: https://github.com/kemzeb Commit: https://github.com/SerenityOS/serenity/commit/b6b4e59bf7 Pull-request: https://github.com/SerenityOS/serenity/pull/21021 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/shannonbooth ✅
2 changed files with 20 additions and 7 deletions
21
AK/URL.cpp
21
AK/URL.cpp
|
@ -260,16 +260,25 @@ bool URL::is_special_scheme(StringView scheme)
|
|||
return scheme.is_one_of("ftp", "file", "http", "https", "ws", "wss");
|
||||
}
|
||||
|
||||
DeprecatedString URL::serialize_path() const
|
||||
// https://url.spec.whatwg.org/#url-path-serializer
|
||||
DeprecatedString URL::serialize_path(ApplyPercentDecoding apply_percent_decoding) const
|
||||
{
|
||||
// If url has an opaque path, then return url’s path.
|
||||
// FIXME: Reimplement this step once we modernize the URL implementation to meet the spec.
|
||||
if (cannot_be_a_base_url())
|
||||
return m_paths[0];
|
||||
StringBuilder builder;
|
||||
for (auto& path : m_paths) {
|
||||
builder.append('/');
|
||||
builder.append(percent_decode(path));
|
||||
|
||||
// Let output be the empty string.
|
||||
StringBuilder output;
|
||||
|
||||
// For each segment of url’s path: append U+002F (/) followed by segment to output.
|
||||
for (auto const& segment : m_paths) {
|
||||
output.append('/');
|
||||
output.append(apply_percent_decoding == ApplyPercentDecoding::Yes ? percent_decode(segment) : segment);
|
||||
}
|
||||
return builder.to_deprecated_string();
|
||||
|
||||
// Return output.
|
||||
return output.to_deprecated_string();
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#concept-url-serializer
|
||||
|
|
6
AK/URL.h
6
AK/URL.h
|
@ -107,7 +107,11 @@ public:
|
|||
m_paths.append("");
|
||||
}
|
||||
|
||||
DeprecatedString serialize_path() const;
|
||||
enum class ApplyPercentDecoding {
|
||||
Yes,
|
||||
No
|
||||
};
|
||||
DeprecatedString serialize_path(ApplyPercentDecoding = ApplyPercentDecoding::Yes) const;
|
||||
DeprecatedString serialize(ExcludeFragment = ExcludeFragment::No) const;
|
||||
DeprecatedString serialize_for_display() const;
|
||||
DeprecatedString to_deprecated_string() const { return serialize(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue