From: GoalSmashers Date: Sat, 26 Oct 2013 09:12:22 +0000 (+0200) Subject: Fixes #155 - broken irregular CSS content. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=12d5178ed3cf258e189c99c5729e1dadcccb123d;p=clean-css.git Fixes #155 - broken irregular CSS content. * ["content"] is an invalid CSS but it was matched as an attribute. * If placed inside content property value it was matched BEFORE we escape all free text. --- diff --git a/History.md b/History.md index d532f8dc..4a394d76 100644 --- a/History.md +++ b/History.md @@ -3,6 +3,11 @@ * Adds simplified and more advanced text escaping / restoring via `EscapeStore` class. +1.1.6 / 2013-xx-xx +================== + +* Fixed issue [#155](https://github.com/GoalSmashers/clean-css/issues/155) - broken irregular CSS content. + 1.1.5 / 2013-10-24 ================== diff --git a/lib/clean.js b/lib/clean.js index 7e1a9c2a..7366e60c 100644 --- a/lib/clean.js +++ b/lib/clean.js @@ -113,7 +113,11 @@ var CleanCSS = { // strip parentheses in attribute values replace(/\[([^\]]+)\]/g, function(match, content) { var eqIndex = content.indexOf('='); - if (eqIndex < 0 && content.indexOf('\'') < 0 && content.indexOf('"') < 0) + var singleQuoteIndex = content.indexOf('\''); + var doubleQuoteIndex = content.indexOf('"'); + if (eqIndex < 0 && singleQuoteIndex < 0 && doubleQuoteIndex < 0) + return match; + if (singleQuoteIndex === 0 || doubleQuoteIndex === 0) return match; var key = content.substring(0, eqIndex); diff --git a/test/unit-test.js b/test/unit-test.js index 64c8743c..17d74b13 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -306,7 +306,8 @@ vows.describe('clean-units').addBatch({ 'special characters': [ 'a{content : " a > div { } "}', 'a{content:" a > div { } "}' - ] + ], + 'with JSON': 'body::before{content:\'{ "current" : "small", "all" : ["small"], "position" : 0 }\'}' }), 'zero values': cssContext({ 'with units': [ @@ -766,6 +767,7 @@ path")}', 'should keep quotation if is a number': 'div[data-number=\'1\']{border-color:red}', 'should keep quotation if starts with a number': 'div[data-type^=\'1something\']{border-color:red}', 'should keep quotation if starts with a hyphen': 'div[data-type$=\'-something\']{border-color:red}', + 'should keep quotation if key only (which is invalid)': 'div["data-type"]', 'should strip quotation if is a word': [ 'a[data-href=\'object\']{border-color:red}', 'a[data-href=object]{border-color:red}'