From 4a8c70b3a53b29f144b9901ba697c3cd19ab0f8d Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Fri, 8 Aug 2025 09:55:38 -0400 Subject: [PATCH] LibWeb: Parse CSS/image URLs using DOMURL::parse DOMURL::parse handles blob URLs. --- Libraries/LibWeb/CSS/Fetch.cpp | 5 ++- .../CSS/StyleValues/ImageStyleValue.cpp | 4 +- Libraries/LibWeb/HTML/ImageRequest.cpp | 7 ++-- .../expected/css-background-blob-url-ref.html | 12 ++++++ .../images/css-background-blob-url-ref.png | Bin 0 -> 3875 bytes .../input/css-background-blob-url.html | 39 ++++++++++++++++++ 6 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 Tests/LibWeb/Screenshot/expected/css-background-blob-url-ref.html create mode 100644 Tests/LibWeb/Screenshot/images/css-background-blob-url-ref.png create mode 100644 Tests/LibWeb/Screenshot/input/css-background-blob-url.html diff --git a/Libraries/LibWeb/CSS/Fetch.cpp b/Libraries/LibWeb/CSS/Fetch.cpp index 1fe56501018..8d40d56d898 100644 --- a/Libraries/LibWeb/CSS/Fetch.cpp +++ b/Libraries/LibWeb/CSS/Fetch.cpp @@ -4,10 +4,10 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include +#include #include #include @@ -38,7 +38,8 @@ static WebIDL::ExceptionOr> fetch_a_styl auto url_string = url_value.visit( [](::URL::URL const& url) { return url.to_string(); }, [](CSS::URL const& url) { return url.url(); }); - auto parsed_url = ::URL::Parser::basic_parse(url_string, base); + + auto parsed_url = DOMURL::parse(url_string, base); if (!parsed_url.has_value()) return WebIDL::SimpleException { WebIDL::SimpleExceptionType::URIError, "Failed to parse URL"sv }; diff --git a/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.cpp index 9bd2489c96d..cbb050cebeb 100644 --- a/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/ImageStyleValue.cpp @@ -7,11 +7,11 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include #include +#include #include #include #include @@ -208,7 +208,7 @@ ValueComparingNonnullRefPtr ImageStyleValue::absolutized(CSSPi }(); if (base_url.has_value()) { - if (auto resolved_url = ::URL::Parser::basic_parse(m_url.url(), *base_url); resolved_url.has_value()) + if (auto resolved_url = DOMURL::parse(m_url.url(), *base_url); resolved_url.has_value()) return ImageStyleValue::create(*resolved_url); } diff --git a/Libraries/LibWeb/HTML/ImageRequest.cpp b/Libraries/LibWeb/HTML/ImageRequest.cpp index c35df4e580a..b1cc275f8c1 100644 --- a/Libraries/LibWeb/HTML/ImageRequest.cpp +++ b/Libraries/LibWeb/HTML/ImageRequest.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include @@ -71,8 +71,9 @@ void ImageRequest::set_state(State state) void ImageRequest::set_current_url(JS::Realm& realm, String url) { m_current_url = move(url); - if (auto url = URL::Parser::basic_parse(m_current_url); url.has_value()) - m_shared_resource_request = SharedResourceRequest::get_or_create(realm, m_page, url.release_value()); + + if (auto parsed_url = DOMURL::parse(m_current_url); parsed_url.has_value()) + m_shared_resource_request = SharedResourceRequest::get_or_create(realm, m_page, parsed_url.release_value()); } // https://html.spec.whatwg.org/multipage/images.html#abort-the-image-request diff --git a/Tests/LibWeb/Screenshot/expected/css-background-blob-url-ref.html b/Tests/LibWeb/Screenshot/expected/css-background-blob-url-ref.html new file mode 100644 index 00000000000..9ab4c8d8fc5 --- /dev/null +++ b/Tests/LibWeb/Screenshot/expected/css-background-blob-url-ref.html @@ -0,0 +1,12 @@ + + + + diff --git a/Tests/LibWeb/Screenshot/images/css-background-blob-url-ref.png b/Tests/LibWeb/Screenshot/images/css-background-blob-url-ref.png new file mode 100644 index 0000000000000000000000000000000000000000..edc00828084116f1de9258dea7e2b68c8065ecdb GIT binary patch literal 3875 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>iV_;yIRn}C%z`*y))5S5QV$R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?d00001 diff --git a/Tests/LibWeb/Screenshot/input/css-background-blob-url.html b/Tests/LibWeb/Screenshot/input/css-background-blob-url.html new file mode 100644 index 00000000000..549af979a49 --- /dev/null +++ b/Tests/LibWeb/Screenshot/input/css-background-blob-url.html @@ -0,0 +1,39 @@ + + + + + + + +
+ + + +