srctree

Robin Linden parent 16962315 49e39cfd
css: Fix crash when encountering keyframes at-rules

inlinesplit
css/parser.h added: 41, removed: 2, total 39
@@ -44,6 +44,28 @@ public:
skip_whitespace_and_comments();
}
 
// https://developer.mozilla.org/en-US/docs/Web/CSS/@keyframes
// Not saved or anything yet, but stops us from crashing when encountering it.
if (starts_with("@keyframes ")) {
advance(std::strlen("@keyframes "));
skip_whitespace_and_comments();
[[maybe_unused]] auto keyframes_name = consume_while([](char c) { return c != '{'; });
consume_char(); // {
skip_whitespace_and_comments();
 
while (peek() != '}') {
[[maybe_unused]] auto rule = parse_rule();
skip_whitespace_and_comments();
}
 
consume_char(); // }
skip_whitespace_and_comments();
 
if (is_eof()) {
break;
}
}
 
rules.push_back(parse_rule());
if (!media_query.empty()) {
rules.back().media_query = std::string{media_query};
 
css/parser_test.cpp added: 41, removed: 2, total 39
@@ -615,5 +615,22 @@ int main() {
expect(check_initial_font_values(body.declarations));
});
 
etest::test("parser: @keyframes doesn't crash the parser", [] {
auto css = R"(
@keyframes toast-spinner {
from {
transform: rotate(0deg)
}
 
to {
transform: rotate(360deg)
}
})"sv;
 
// No rules produced (yet!) since this isn't handled aside from not crashing.
auto rules = css::parse(css);
expect(rules.empty());
});
 
return etest::run_all_tests();
}