From 90be84e87800d6a8c6e19ad22b4e29d1eb02a353 Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Mon, 28 Jan 2013 16:32:04 +0100 Subject: [PATCH] Fixes #59 - invalid 'content' property processing if a selector with 'content' substring is matched earlier on. --- lib/clean.js | 11 ++++++++++- test/unit-test.js | 6 ++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/clean.js b/lib/clean.js index b9758b3a..c0035f11 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -40,6 +40,7 @@ var CleanCSS = { data = data.replace.apply(data, arguments); }; var lineBreak = process.platform == 'win32' ? '\r\n' : '\n'; + this.lineBreak = lineBreak; options = options || {}; @@ -338,6 +339,8 @@ var CleanCSS = { nextEnd = 0, cursor = 0, matchedParenthesis = null; + var allowedPrefixes = [' ', '{', ';', this.lineBreak]; + var skipBy = 'content'.length; // Find either first (matchedParenthesis == null) or second matching // parenthesis so that we can determine boundaries of content block. @@ -382,7 +385,13 @@ var CleanCSS = { if (nextStart == -1) break; - nextStart = nextParenthesis(nextStart + 7); + // skip by `skipBy` bytes if matched declaration is not a property but ID, class name or a some substring + if (allowedPrefixes.indexOf(data[nextStart - 1]) == -1) { + nextEnd += skipBy; + continue; + } + + nextStart = nextParenthesis(nextStart + skipBy); nextEnd = nextParenthesis(nextStart); if (nextStart == -1 || nextEnd == -1) break; diff --git a/test/unit-test.js b/test/unit-test.js index 11bdf451..f8747661 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -122,6 +122,12 @@ vows.describe('clean-units').addBatch({ 'whitespace in media queries': [ '@media ( min-width: 980px ) {\n#page .span4 {\nwidth: 250px;\n}\n\n.row {\nmargin-left: -10px;\n}\n}', '@media (min-width:980px){#page .span4{width:250px}.row{margin-left:-10px}}', + ], + 'in content preceded by #content': '#content{}#foo{content:"\00BB "}', + 'in content preceded by .content': '.content{}#foo{content:"\00BB "}', + 'in content preceded by line break': [ + '.content{}#foo{' + lineBreak + 'content:"\00BB "}', + '.content{}#foo{content:"\00BB "}' ] }), 'line breaks': cssContext({ -- 2.34.1