From 8b3bcf9c0fe4dcb733502ee887bb5f5901e4e58b Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 11 Sep 2024 17:53:39 +0100 Subject: [PATCH] LibWeb: Reduce unnecessary debug spam from parse_as_sizes_attribute() Logging a parse error when the attribute is not present, is not useful, but does fill the debug log with errors that hide any real parsing errors. This patch introduces an early-out in this situation to prevent this spam. --- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 76f2d06220c..93269ec707a 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -7932,10 +7932,15 @@ private: }; // https://html.spec.whatwg.org/multipage/images.html#parsing-a-sizes-attribute -LengthOrCalculated Parser::Parser::parse_as_sizes_attribute([[maybe_unused]] DOM::Element const& element, HTML::HTMLImageElement const* img) +LengthOrCalculated Parser::Parser::parse_as_sizes_attribute(DOM::Element const& element, HTML::HTMLImageElement const* img) { // When asked to parse a sizes attribute from an element element, with an img element or null img: + // AD-HOC: If element has no sizes attribute, this algorithm always logs a parse error and then returns 100vw. + // The attribute is optional, so avoid spamming the debug log with false positives by just returning early. + if (!element.has_attribute(HTML::AttributeNames::sizes)) + return Length(100, Length::Type::Vw); + // 1. Let unparsed sizes list be the result of parsing a comma-separated list of component values // from the value of element's sizes attribute (or the empty string, if the attribute is absent). // NOTE: The sizes attribute has already been tokenized into m_token_stream by this point.