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.
This commit is contained in:
Sam Atkins 2024-09-11 17:53:39 +01:00 committed by Andreas Kling
commit 8b3bcf9c0f
Notes: github-actions[bot] 2024-09-12 05:40:00 +00:00

View file

@ -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.