AK: Correct faulty logic in file slash state in basic URL parsing

We were not correctly decrementing the pointer in the case that either
the base URL was non-null or the base URL's scheme was not a file.
This commit is contained in:
Shannon Booth 2023-07-04 21:12:33 +12:00 committed by Andreas Kling
parent a809d1634f
commit b76972ff32
Notes: sideshowbarker 2024-07-17 03:51:15 +09:00

View file

@ -823,22 +823,23 @@ URL URLParser::parse(StringView raw_input, Optional<URL> const& base_url, Option
state = State::FileHost;
}
// 2. Otherwise:
// 1. If base is non-null and bases scheme is "file", then:
else if (base_url.has_value() && base_url->m_scheme == "file") {
// 1. Set urls host to bases host.
url->m_paths = base_url->m_paths;
url->m_paths.remove(url->m_paths.size() - 1);
else {
// 1. If base is non-null and bases scheme is "file", then:
if (base_url.has_value() && base_url->m_scheme == "file") {
// 1. Set urls host to bases host.
url->m_paths = base_url->m_paths;
url->m_paths.remove(url->m_paths.size() - 1);
// 2. If the code point substring from pointer to the end of input does not start with a Windows drive letter and bases path[0] is a normalized Windows drive letter, then append bases path[0] to urls path.
auto substring_from_pointer = input.substring_view(iterator - input.begin()).as_string();
if (!starts_with_windows_drive_letter(substring_from_pointer) && is_normalized_windows_drive_letter(base_url->m_paths[0]))
url->append_path(base_url->m_paths[0], URL::ApplyPercentEncoding::No);
// 2. If the code point substring from pointer to the end of input does not start with a Windows drive letter and bases path[0] is a normalized Windows drive letter, then append bases path[0] to urls path.
auto substring_from_pointer = input.substring_view(iterator - input.begin()).as_string();
if (!starts_with_windows_drive_letter(substring_from_pointer) && is_normalized_windows_drive_letter(base_url->m_paths[0]))
url->append_path(base_url->m_paths[0], URL::ApplyPercentEncoding::No);
}
// FIXME: This should be done outside of this file block, see below.
// 2. Set state to path state, and decrease pointer by 1.
state = State::Path;
continue;
}
// FIXME: 2. Set state to path state, and decrease pointer by 1.
break;
// -> file host state, https://url.spec.whatwg.org/#file-host-state
case State::FileHost: