AK: Use base URL when the specified URL is empty

This commit is contained in:
Thiago Henrique Hupner 2022-12-27 16:17:30 -03:00 committed by Andrew Kaster
parent 96d3d3b0fe
commit 401bc13776
Notes: sideshowbarker 2024-07-17 02:08:15 +09:00
2 changed files with 10 additions and 1 deletions

View file

@ -201,7 +201,7 @@ URL URLParser::parse(StringView raw_input, URL const* base_url, Optional<URL> ur
{
dbgln_if(URL_PARSER_DEBUG, "URLParser::parse: Parsing '{}'", raw_input);
if (raw_input.is_empty())
return {};
return base_url ? *base_url : URL {};
if (raw_input.starts_with("data:"sv)) {
auto maybe_url = parse_data_url(raw_input);

View file

@ -9,6 +9,7 @@
#include <AK/Base64.h>
#include <AK/URL.h>
#include <AK/URLParser.h>
TEST_CASE(construct)
{
@ -406,3 +407,11 @@ TEST_CASE(complete_file_url_with_base)
EXPECT(sub_url.is_valid());
EXPECT_EQ(sub_url.path(), "/home/js/app.js");
}
TEST_CASE(empty_url_with_base_url)
{
URL base_url { "https://foo.com/"sv };
URL parsed_url = URLParser::parse(""sv, &base_url);
EXPECT_EQ(parsed_url.is_valid(), true);
EXPECT(base_url.equals(parsed_url));
}