Skip to content

Commit

Permalink
css: Treat media-queries that fail to parse as always false
Browse files Browse the repository at this point in the history
  • Loading branch information
robinlinden committed Nov 9, 2023
1 parent 4045095 commit d03ac09
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions css/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ StyleSheet Parser::parse_rules() {
media_query = MediaQuery::parse(*tmp_query);
if (!media_query) {
spdlog::warn("Unable to parse media query: '{}'", *tmp_query);
media_query = MediaQuery{MediaQuery::False{}};
}
consume_char(); // {
skip_whitespace_and_comments();
Expand Down
2 changes: 1 addition & 1 deletion css/parser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ int main() {
etest::test("parser: bad media query", [] {
auto rules = css::parse("@media (rip: 0) { p { font-size: 10px; } }").rules;
auto const &rule = rules.at(0);
expect_eq(rule.media_query, std::nullopt);
expect_eq(rule.media_query, css::MediaQuery{css::MediaQuery::False{}});
expect_eq(rule.selectors, std::vector{"p"s});
require_eq(rule.declarations.size(), std::size_t{1});
expect_eq(rule.declarations.at(css::PropertyId::FontSize), "10px");
Expand Down

0 comments on commit d03ac09

Please sign in to comment.