From 5ab4c71ecada88a5d55ad77358722997d982a644 Mon Sep 17 00:00:00 2001 From: Alex Schneider Date: Tue, 7 Nov 2017 13:06:36 +0100 Subject: [PATCH] Fix handling of CDO and CDC tokens --- extcss3/minifier/tree.c | 16 ++++++++++++++++ tests/minify_special_cases.phpt | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/extcss3/minifier/tree.c b/extcss3/minifier/tree.c index e0f69c7..24af4ec 100644 --- a/extcss3/minifier/tree.c +++ b/extcss3/minifier/tree.c @@ -71,6 +71,22 @@ extcss3_rule *extcss3_create_tree(extcss3_token **token, extcss3_token *max, uns return tree; } } + // Pseudo-rule for and tokens in a non top-level + else if (((*token)->type == EXTCSS3_TYPE_CDO) || ((*token)->type == EXTCSS3_TYPE_CDC)) { + // See ยง 5.4.1.: https://www.w3.org/TR/css-syntax-3/#consume-a-list-of-rules + if (level > 0) { + rule->base_selector = rule->last_selector = *token; + + // Fork the next rule + if (EXTCSS3_SUCCESS != _extcss3_tree_fork_rule(&rule, error)) { + return _extcss3_set_error_code(error, *error, tree); + } + } + + *token = (*token)->next; + + continue; + } // Pseudo-rule for the token if ((*token)->type == EXTCSS3_TYPE_EOF) { diff --git a/tests/minify_special_cases.phpt b/tests/minify_special_cases.phpt index 55f259a..a99c644 100644 --- a/tests/minify_special_cases.phpt +++ b/tests/minify_special_cases.phpt @@ -41,6 +41,9 @@ var_dump($oProcessor->minify($sCSS)); $sCSS = ':not( x ) foo {a:b;}'; var_dump($oProcessor->minify($sCSS)); +$sCSS = ' } --> '; +var_dump($oProcessor->minify($sCSS)); + ?> ===DONE=== --EXPECT-- @@ -50,4 +53,5 @@ string(105) "x{content:'\A\B'}y{background:url('wallpaper.jpg')}#\31st{color:red string(10) "x{y:1px\9}" string(48) "@media(min-width:30em)and (max-height:60em){a:b}" string(16) ":not(x) foo{a:b}" +string(28) "@media screen{}" ===DONE===