LibWeb/CSS: Use ErrorReporter for value-parsing errors

Also remove some redundant reporting for `<urange>` parsing errors.
This commit is contained in:
Sam Atkins 2025-07-23 11:04:17 +01:00
commit cebdcd9f69
Notes: github-actions[bot] 2025-08-04 09:52:05 +00:00
5 changed files with 239 additions and 61 deletions

View file

@ -20,6 +20,7 @@
#include <LibWeb/CSS/CSSStyleSheet.h>
#include <LibWeb/CSS/FontFace.h>
#include <LibWeb/CSS/MediaList.h>
#include <LibWeb/CSS/Parser/ErrorReporter.h>
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/PropertyName.h>
#include <LibWeb/CSS/Sizing.h>
@ -1750,7 +1751,11 @@ LengthOrCalculated Parser::parse_as_sizes_attribute(DOM::Element const& element,
remove_all_consecutive_whitespace_tokens_from_the_end_of(unparsed_size);
if (unparsed_size.is_empty()) {
log_parse_error();
dbgln_if(CSS_PARSER_DEBUG, "-> Failed in step 3.1; all whitespace");
ErrorReporter::the().report(InvalidValueError {
.value_type = "sizes attribute"_fly_string,
.value_string = m_token_stream.dump_string(),
.description = "Failed in step 3.1; all whitespace"_string,
});
continue;
}
@ -1764,7 +1769,11 @@ LengthOrCalculated Parser::parse_as_sizes_attribute(DOM::Element const& element,
unparsed_size.take_last();
} else {
log_parse_error();
dbgln_if(CSS_PARSER_DEBUG, "-> Failed in step 3.2; couldn't parse {} as a <source-size-value>", unparsed_size.last().to_debug_string());
ErrorReporter::the().report(InvalidValueError {
.value_type = "sizes attribute"_fly_string,
.value_string = m_token_stream.dump_string(),
.description = "Failed in step 3.2; couldn't parse {} as a <source-size-value>"_string,
});
continue;
}
@ -1789,7 +1798,11 @@ LengthOrCalculated Parser::parse_as_sizes_attribute(DOM::Element const& element,
// 1. If this was not the last item in unparsed sizes list, that is a parse error.
if (i != unparsed_sizes_list.size() - 1) {
log_parse_error();
dbgln_if(CSS_PARSER_DEBUG, "-> Failed in step 3.4.1; is unparsed size #{}, count {}", i, unparsed_sizes_list.size());
ErrorReporter::the().report(InvalidValueError {
.value_type = "sizes attribute"_fly_string,
.value_string = m_token_stream.dump_string(),
.description = MUST(String::formatted("Failed in step 3.4.1; is unparsed size #{}, count {}", i, unparsed_sizes_list.size())),
});
}
// 2. If size is not auto, then return size. Otherwise, continue.