Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LibWeb/URL: Add strip_trailing_spaces_from_an_opaque_path() #21021

Merged
merged 3 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions AK/URL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

@ADKaster ADKaster Sep 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. Kind of weird that the spec has a bulleted list for this instead of a numbered list. Might be worth a spec issue in https://github.com/whatwg/url if you're feeling speccy :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea I wasn't too sure if this was intentional too. I'll file an issue there 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened an issue at whatwg/url#786

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
Expand Down
6 changes: 5 additions & 1 deletion AK/URL.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ class URL {
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(); }
Expand Down