mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Add spec comments to URL::serialize
This commit is contained in:
parent
177b04dcfc
commit
c8da880806
Notes:
sideshowbarker
2024-07-17 03:30:41 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/c8da880806 Pull-request: https://github.com/SerenityOS/serenity/pull/20187
1 changed files with 38 additions and 19 deletions
57
AK/URL.cpp
57
AK/URL.cpp
|
@ -299,49 +299,68 @@ DeprecatedString URL::serialize(ExcludeFragment exclude_fragment) const
|
||||||
{
|
{
|
||||||
if (m_scheme == "data")
|
if (m_scheme == "data")
|
||||||
return serialize_data_url();
|
return serialize_data_url();
|
||||||
StringBuilder builder;
|
|
||||||
builder.append(m_scheme);
|
|
||||||
builder.append(':');
|
|
||||||
|
|
||||||
|
// 1. Let output be url’s scheme and U+003A (:) concatenated.
|
||||||
|
StringBuilder output;
|
||||||
|
output.append(m_scheme);
|
||||||
|
output.append(':');
|
||||||
|
|
||||||
|
// 2. If url’s host is non-null:
|
||||||
if (!m_host.is_null()) {
|
if (!m_host.is_null()) {
|
||||||
builder.append("//"sv);
|
// 1. Append "//" to output.
|
||||||
|
output.append("//"sv);
|
||||||
|
|
||||||
|
// 2. If url includes credentials, then:
|
||||||
if (includes_credentials()) {
|
if (includes_credentials()) {
|
||||||
builder.append(m_username);
|
// 1. Append url’s username to output.
|
||||||
|
output.append(m_username);
|
||||||
|
|
||||||
|
// 2. If url’s password is not the empty string, then append U+003A (:), followed by url’s password, to output.
|
||||||
if (!m_password.is_empty()) {
|
if (!m_password.is_empty()) {
|
||||||
builder.append(':');
|
output.append(':');
|
||||||
builder.append(m_password);
|
output.append(m_password);
|
||||||
}
|
}
|
||||||
builder.append('@');
|
|
||||||
|
// 3. Append U+0040 (@) to output.
|
||||||
|
output.append('@');
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append(m_host);
|
// 3. Append url’s host, serialized, to output.
|
||||||
|
output.append(m_host);
|
||||||
|
|
||||||
|
// 4. If url’s port is non-null, append U+003A (:) followed by url’s port, serialized, to output.
|
||||||
if (m_port.has_value())
|
if (m_port.has_value())
|
||||||
builder.appendff(":{}", *m_port);
|
output.appendff(":{}", *m_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3. If url’s host is null, url does not have an opaque path, url’s path’s size is greater than 1, and url’s path[0] is the empty string, then append U+002F (/) followed by U+002E (.) to output.
|
||||||
|
// 4. Append the result of URL path serializing url to output.
|
||||||
|
// FIXME: Implement this closer to spec steps.
|
||||||
if (cannot_be_a_base_url()) {
|
if (cannot_be_a_base_url()) {
|
||||||
builder.append(m_paths[0]);
|
output.append(m_paths[0]);
|
||||||
} else {
|
} else {
|
||||||
if (m_host.is_null() && m_paths.size() > 1 && m_paths[0].is_empty())
|
if (m_host.is_null() && m_paths.size() > 1 && m_paths[0].is_empty())
|
||||||
builder.append("/."sv);
|
output.append("/."sv);
|
||||||
for (auto& segment : m_paths) {
|
for (auto& segment : m_paths) {
|
||||||
builder.append('/');
|
output.append('/');
|
||||||
builder.append(segment);
|
output.append(segment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 5. If url’s query is non-null, append U+003F (?), followed by url’s query, to output.
|
||||||
if (!m_query.is_null()) {
|
if (!m_query.is_null()) {
|
||||||
builder.append('?');
|
output.append('?');
|
||||||
builder.append(m_query);
|
output.append(m_query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 6. If exclude fragment is false and url’s fragment is non-null, then append U+0023 (#), followed by url’s fragment, to output.
|
||||||
if (exclude_fragment == ExcludeFragment::No && !m_fragment.is_null()) {
|
if (exclude_fragment == ExcludeFragment::No && !m_fragment.is_null()) {
|
||||||
builder.append('#');
|
output.append('#');
|
||||||
builder.append(m_fragment);
|
output.append(m_fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.to_deprecated_string();
|
// 7. Return output.
|
||||||
|
return output.to_deprecated_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://url.spec.whatwg.org/#url-rendering
|
// https://url.spec.whatwg.org/#url-rendering
|
||||||
|
|
Loading…
Reference in a new issue