From 15cdb702c2fa13e7612a24338029295237b17af6 Mon Sep 17 00:00:00 2001 From: K-Adam Date: Wed, 28 Jul 2021 11:49:08 +0200 Subject: [PATCH] LibWeb: Handle comment blocks when skipping unknown @-rules This css definition was parsed incorrectly before: ```css @media screen { /* Unclosed bracket in comment { */ body { background: red; } } ``` --- .../LibWeb/CSS/Parser/DeprecatedCSSParser.cpp | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp index 92d7d636a4..0163fd733b 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/DeprecatedCSSParser.cpp @@ -1428,17 +1428,28 @@ public: } // FIXME: We ignore other @-rules completely for now. - while (peek() != 0 && peek() != '{') - consume_one(); int level = 0; - for (;;) { + bool in_comment = false; + + while (peek() != 0) { auto ch = consume_one(); - if (ch == '{') { - ++level; - } else if (ch == '}') { - --level; - if (level == 0) - break; + + if (!in_comment) { + if (ch == '/' && peek() == '*') { + consume_one(); + in_comment = true; + } else if (ch == '{') { + ++level; + } else if (ch == '}') { + --level; + if (level == 0) + break; + } + } else { + if (ch == '*' && peek() == '/') { + consume_one(); + in_comment = false; + } } } }