From ea566579e5442f46de64bcfd2d575ee5f7f4e9a8 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Wed, 25 Jan 2017 11:12:14 +0100 Subject: [PATCH] Fixes #872 - edge case in tokenization. Why: * On closing curly brace `}` both `ruleToken` and `propertyToken` should be nullified to prevent incorrect property assignments. --- History.md | 1 + lib/tokenizer/tokenize.js | 1 + test/tokenizer/tokenize-test.js | 57 +++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/History.md b/History.md index fa8f924c..9fb8f3fd 100644 --- a/History.md +++ b/History.md @@ -4,6 +4,7 @@ * Fixed issue [#866](https://github.com/jakubpawlowicz/clean-css/issues/866) - edge case in `inline` option. * Fixed issue [#867](https://github.com/jakubpawlowicz/clean-css/issues/867) - skip optimizing variable values. * Fixed issue [#868](https://github.com/jakubpawlowicz/clean-css/issues/868) - accept absolute paths in input hash. +* Fixed issue [#872](https://github.com/jakubpawlowicz/clean-css/issues/872) - edge case in CSS tokenization. [4.0.0 / 2017-01-23](https://github.com/jakubpawlowicz/clean-css/compare/v3.4.24...v4.0.0) ================== diff --git a/lib/tokenizer/tokenize.js b/lib/tokenizer/tokenize.js index 7ba9282c..9fa1b1a9 100644 --- a/lib/tokenizer/tokenize.js +++ b/lib/tokenizer/tokenize.js @@ -319,6 +319,7 @@ function intoTokens(source, externalContext, internalContext, isNested) { buffer = []; } else if (character == Marker.CLOSE_CURLY_BRACKET && level == Level.RULE) { // close brace after a rule, e.g. a{color:red;}<-- + propertyToken = null; ruleToken = null; newTokens = allTokens; diff --git a/test/tokenizer/tokenize-test.js b/test/tokenizer/tokenize-test.js index 7ae8cad9..2b4cff52 100644 --- a/test/tokenizer/tokenize-test.js +++ b/test/tokenizer/tokenize-test.js @@ -1631,6 +1631,63 @@ vows.describe(tokenize) ] ] ], + '@apply in a new rule after variable is last in previous one 1234': [ + '.block-1{fill:var(--test1)}.block-2{@apply(--test2)}', + [ + [ + 'rule', + [ + [ + 'rule-scope', + '.block-1', + [ + [1, 0, undefined] + ] + ] + ], + [ + [ + 'property', + [ + 'property-name', + 'fill', + [ + [1, 9, undefined] + ] + ], + [ + 'property-value', + 'var(--test1)', + [ + [1, 14, undefined] + ] + ] + ] + ] + ], + [ + 'rule', + [ + [ + 'rule-scope', + '.block-2', + [ + [1, 27, undefined] + ] + ] + ], + [ + [ + 'at-rule', + '@apply(--test2)', + [ + [1, 36, undefined] + ] + ] + ] + ] + ] + ], 'media query': [ '@media (min-width:980px){}', [ -- 2.34.1