LibWeb: Do not fetch empty CSS URLs

If a CSS rule has a URL like `url("")`, it would resolve to the document
URL itself. There isn't a context in which this would result in a valid
resource, so the spec tells us to drop it.

No test here because there isn't really a way to know when a CSS URL is
fetched. We could use PerformanceResourceTiming, but that is only for
HTTP(S) URLs. There is already an existing test for serialization of
empty URLs, which still passes.
This commit is contained in:
Timothy Flynn 2025-11-12 12:06:53 -05:00 committed by Jelle Raaijmakers
parent d8ec204be8
commit 0cb9f4b66f
Notes: github-actions[bot] 2025-11-12 17:31:53 +00:00

View file

@ -40,6 +40,12 @@ static GC::Ptr<Fetch::Infrastructure::Request> fetch_a_style_resource_impl(Style
[](::URL::URL const& url) { return url.to_string(); },
[](CSS::URL const& url) { return url.url(); });
// https://drafts.csswg.org/css-values-4/#url-empty
// If the value of the <url> is the empty string (like url("") or url()), the url must resolve to an invalid
// resource (similar to what the url about:invalid does).
if (url_string.is_empty())
return {};
auto parsed_url = DOMURL::parse(url_string, base);
if (!parsed_url.has_value())
return {};