Explorar el Código

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`.
Linus Groh hace 2 años
padre
commit
caa13bf41d

+ 3 - 1
Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Responses.cpp

@@ -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 response’s 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);