mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
AK: Implement steps for state override in URL parser
This commit is contained in:
parent
500097de82
commit
7ef4689383
1 changed files with 44 additions and 16 deletions
|
@ -320,21 +320,36 @@ URL URLParser::parse(StringView raw_input, Optional<URL> const& base_url, Option
|
||||||
}
|
}
|
||||||
// 2. Otherwise, if c is U+003A (:), then:
|
// 2. Otherwise, if c is U+003A (:), then:
|
||||||
else if (code_point == ':') {
|
else if (code_point == ':') {
|
||||||
// FIXME: 1. If state override is given, then:
|
// 1. If state override is given, then:
|
||||||
if (false) {
|
if (state_override.has_value()) {
|
||||||
// FIXME: 1. If url’s scheme is a special scheme and buffer is not a special scheme, then return.
|
// 1. If url’s scheme is a special scheme and buffer is not a special scheme, then return.
|
||||||
// FIXME: 2. If url’s scheme is a special scheme and buffer is not a special scheme, then return.
|
if (URL::is_special_scheme(url->scheme()) && !URL::is_special_scheme(buffer.string_view()))
|
||||||
// FIXME: 3. If url includes credentials or has a non-null port, and buffer is "file", then return.
|
return *url;
|
||||||
// FIXME: 4. If url’s scheme is "file" and its host is an empty host, then return.
|
|
||||||
|
// 2. If url’s scheme is not a special scheme and buffer is a special scheme, then return.
|
||||||
|
if (!URL::is_special_scheme(url->scheme()) && URL::is_special_scheme(buffer.string_view()))
|
||||||
|
return *url;
|
||||||
|
|
||||||
|
// 3. If url includes credentials or has a non-null port, and buffer is "file", then return.
|
||||||
|
if ((url->includes_credentials() || url->port().has_value()) && buffer.string_view() == "file"sv)
|
||||||
|
return *url;
|
||||||
|
|
||||||
|
// 4. If url’s scheme is "file" and its host is an empty host, then return.
|
||||||
|
if (url->scheme() == "file"sv && url->host().is_empty())
|
||||||
|
return *url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Set url’s scheme to buffer.
|
// 2. Set url’s scheme to buffer.
|
||||||
url->m_scheme = buffer.to_deprecated_string();
|
url->m_scheme = buffer.to_deprecated_string();
|
||||||
|
|
||||||
// FIXME: 3. If state override is given, then:
|
// 3. If state override is given, then:
|
||||||
if (false) {
|
if (state_override.has_value()) {
|
||||||
// FIXME: 1. If url’s port is url’s scheme’s default port, then set url’s port to null.
|
// 1. If url’s port is url’s scheme’s default port, then set url’s port to null.
|
||||||
// FIXME: 2. Return.
|
if (url->port() == URL::default_port_for_scheme(url->scheme()))
|
||||||
|
url->m_port = {};
|
||||||
|
|
||||||
|
// 2. Return.
|
||||||
|
return *url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Set buffer to the empty string.
|
// 4. Set buffer to the empty string.
|
||||||
|
@ -634,7 +649,9 @@ URL URLParser::parse(StringView raw_input, Optional<URL> const& base_url, Option
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: 2. If state override is given and state override is hostname state, then return.
|
// 2. If state override is given and state override is hostname state, then return.
|
||||||
|
if (state_override.has_value() && *state_override == State::Hostname)
|
||||||
|
return *url;
|
||||||
|
|
||||||
// 3. Let host be the result of host parsing buffer with url is not special.
|
// 3. Let host be the result of host parsing buffer with url is not special.
|
||||||
auto host = parse_host(buffer.string_view(), !url->is_special());
|
auto host = parse_host(buffer.string_view(), !url->is_special());
|
||||||
|
@ -662,7 +679,9 @@ URL URLParser::parse(StringView raw_input, Optional<URL> const& base_url, Option
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: 2. Otherwise, if state override is given, buffer is the empty string, and either url includes credentials or url’s port is non-null, return.
|
// 2. Otherwise, if state override is given, buffer is the empty string, and either url includes credentials or url’s port is non-null, return.
|
||||||
|
if (state_override.has_value() && buffer.is_empty() && (url->includes_credentials() || url->port().has_value()))
|
||||||
|
return *url;
|
||||||
|
|
||||||
// 3. Let host be the result of host parsing buffer with url is not special.
|
// 3. Let host be the result of host parsing buffer with url is not special.
|
||||||
auto host = parse_host(buffer.string_view(), !url->is_special());
|
auto host = parse_host(buffer.string_view(), !url->is_special());
|
||||||
|
@ -676,7 +695,10 @@ URL URLParser::parse(StringView raw_input, Optional<URL> const& base_url, Option
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
state = State::Port;
|
state = State::Port;
|
||||||
|
|
||||||
// FIXME: 6. If state override is given, then return.
|
// 6. If state override is given, then return.
|
||||||
|
if (state_override.has_value())
|
||||||
|
return *url;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -732,7 +754,9 @@ URL URLParser::parse(StringView raw_input, Optional<URL> const& base_url, Option
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: 2. If state override is given, then return.
|
// 2. If state override is given, then return.
|
||||||
|
if (state_override.has_value())
|
||||||
|
return *url;
|
||||||
|
|
||||||
// 3. Set state to path start state and decrease pointer by 1.
|
// 3. Set state to path start state and decrease pointer by 1.
|
||||||
state = State::PathStart;
|
state = State::PathStart;
|
||||||
|
@ -855,7 +879,9 @@ URL URLParser::parse(StringView raw_input, Optional<URL> const& base_url, Option
|
||||||
// 1. Set url’s host to the empty string.
|
// 1. Set url’s host to the empty string.
|
||||||
url->m_host = "";
|
url->m_host = "";
|
||||||
|
|
||||||
// FIXME: 2. If state override is given, then return.
|
// 2. If state override is given, then return.
|
||||||
|
if (state_override.has_value())
|
||||||
|
return *url;
|
||||||
|
|
||||||
// 3. Set state to path start state.
|
// 3. Set state to path start state.
|
||||||
state = State::PathStart;
|
state = State::PathStart;
|
||||||
|
@ -877,7 +903,9 @@ URL URLParser::parse(StringView raw_input, Optional<URL> const& base_url, Option
|
||||||
// 4. Set url’s host to host.
|
// 4. Set url’s host to host.
|
||||||
url->m_host = host.release_value();
|
url->m_host = host.release_value();
|
||||||
|
|
||||||
// FIXME: 5. If state override is given, then return.
|
// 5. If state override is given, then return.
|
||||||
|
if (state_override.has_value())
|
||||||
|
return *url;
|
||||||
|
|
||||||
// 6. Set buffer to the empty string and state to path start state.
|
// 6. Set buffer to the empty string and state to path start state.
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue