From: Jakub Pawlowicz Date: Wed, 4 Jan 2017 20:24:26 +0000 (+0100) Subject: Fixes #460 - unescaped semicolon in selector. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=d8364dc446a01b6620221ecf15fc877bb1c5c48f;p=clean-css.git Fixes #460 - unescaped semicolon in selector. Why: * Such rules should be dropped. Warnings are already in place. --- diff --git a/History.md b/History.md index 61881d71..fc747613 100644 --- a/History.md +++ b/History.md @@ -12,6 +12,7 @@ * Splits `inliner` option into `inlineRequest` and `inlineTimeout`. * Fixed issue [#209](https://github.com/jakubpawlowicz/clean-css/issues/209) - adds output formatting via `beautify` flag. * Fixed issue [#432](https://github.com/jakubpawlowicz/clean-css/issues/432) - adds URLs normalization. +* Fixed issue [#460](https://github.com/jakubpawlowicz/clean-css/issues/460) - unescaped semicolon in selector. * Fixed issue [#657](https://github.com/jakubpawlowicz/clean-css/issues/657) - adds property name validation. * Fixed issue [#685](https://github.com/jakubpawlowicz/clean-css/issues/685) - adds lowercasing hex colors optimization. * Fixed issue [#686](https://github.com/jakubpawlowicz/clean-css/issues/686) - adds rounding precision for all units. diff --git a/lib/optimizer/tidy-rules.js b/lib/optimizer/tidy-rules.js index 61231c36..a57fec7d 100644 --- a/lib/optimizer/tidy-rules.js +++ b/lib/optimizer/tidy-rules.js @@ -22,7 +22,7 @@ function hasInvalidCharacters(value) { // continue as always } else if (character == Marker.SINGLE_QUOTE || character == Marker.DOUBLE_QUOTE) { isQuote = !isQuote; - } else if (!isQuote && (character == Marker.CLOSE_BRACE || character == Marker.EXCLAMATION || character == LESS_THAN)) { + } else if (!isQuote && (character == Marker.CLOSE_BRACE || character == Marker.EXCLAMATION || character == LESS_THAN || character == Marker.SEMICOLON)) { isInvalid = true; break; } else if (!isQuote && i === 0 && RELATION_PATTERN.test(character)) { diff --git a/lib/tokenizer/tokenize.js b/lib/tokenizer/tokenize.js index 29b15b0a..b38ec565 100644 --- a/lib/tokenizer/tokenize.js +++ b/lib/tokenizer/tokenize.js @@ -147,7 +147,7 @@ function intoTokens(source, externalContext, internalContext, isNested) { buffer.push(character); roundBracketLevel--; - } else if (character == Marker.SEMICOLON && level == Level.BLOCK) { + } else if (character == Marker.SEMICOLON && level == Level.BLOCK && buffer[0] == Marker.AT) { // semicolon ending rule at block level, e.g. @import '...';<-- serializedBuffer = buffer.join('').trim(); allTokens.push([Token.AT_RULE, serializedBuffer, [originalMetadata(metadata, serializedBuffer, externalContext)]]); diff --git a/test/optimizer/basic-test.js b/test/optimizer/basic-test.js index 6c95da4b..7859d099 100644 --- a/test/optimizer/basic-test.js +++ b/test/optimizer/basic-test.js @@ -117,6 +117,10 @@ vows.describe('simple optimizations') '>.funky{background:red}', '' ], + 'invalid characters #4 - semicolon': [ + 'body;{body}', + '' + ], 'missing semicolon and brace in the middle': [ 'body{color:red a{color:blue;}', '' diff --git a/test/tokenizer/tokenize-test.js b/test/tokenizer/tokenize-test.js index 54df4dff..fe3f7986 100644 --- a/test/tokenizer/tokenize-test.js +++ b/test/tokenizer/tokenize-test.js @@ -3639,6 +3639,24 @@ vows.describe(tokenize) ] ] ] + ], + 'unexpected semicolon at root level': [ + 'body;{body}', + [ + [ + 'rule', + [ + [ + 'rule-scope', + 'body;', + [ + [1, 0, undefined] + ] + ] + ], + [] + ] + ] ] }) )