LibWeb: Fix URL parsing in Response::location_url()

We need to use URLParser in order to provide a base URL. This makes it
work for the common case of `Location: /some/path`.
This commit is contained in:
Linus Groh 2022-10-25 23:03:54 +01:00
parent fd042dce55
commit caa13bf41d
Notes: sideshowbarker 2024-07-17 08:35:21 +09:00

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/URLParser.h>
#include <LibJS/Heap/Heap.h>
#include <LibJS/Runtime/VM.h>
#include <LibWeb/Bindings/MainThreadVM.h>
@ -103,7 +104,8 @@ ErrorOr<Optional<AK::URL>> Response::location_url(Optional<String> const& reques
return Optional<AK::URL> {};
// 3. If location is a header value, then set location to the result of parsing location with responses URL.
auto location = AK::URL { StringView { location_values->first() } };
auto base_url = *url();
auto location = AK::URLParser::parse(location_values->first(), &base_url);
if (!location.is_valid())
return Error::from_string_view("Invalid 'Location' header URL"sv);