From: silverwind Date: Sun, 28 Feb 2016 02:04:29 +0000 (+0100) Subject: Fix whitespace removal with escaped joining characters X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=38e79c07c48b91e8db5d4a33437f9d51c4a112c2;p=clean-css.git Fix whitespace removal with escaped joining characters --- diff --git a/lib/selectors/clean-up.js b/lib/selectors/clean-up.js index 3c105ec4..6bb17b99 100644 --- a/lib/selectors/clean-up.js +++ b/lib/selectors/clean-up.js @@ -6,6 +6,15 @@ function selectorSorter(s1, s2) { return s1[0] > s2[0] ? 1 : -1; } +function whitespaceReplacements(_, p1, p2, p3) { + if (p1 && p2 && p3.length) + return p1 + p2 + ' '; + else if (p1 && p2) + return p1 + p2; + else + return p2; +} + var CleanUp = { selectors: function (selectors, removeUnsupported, adjacentSpace) { var list = []; @@ -16,7 +25,7 @@ var CleanUp = { var reduced = selector[0] .replace(/\s+/g, ' ') .replace(/ ?, ?/g, ',') - .replace(/\s*([>\+\~])\s*/g, '$1') + .replace(/\s*(\\)?([>+~])(\s*)/g, whitespaceReplacements) .trim(); if (adjacentSpace && reduced.indexOf('nav') > 0) diff --git a/test/selectors/simple-test.js b/test/selectors/simple-test.js index 665bc312..2fcd7214 100644 --- a/test/selectors/simple-test.js +++ b/test/selectors/simple-test.js @@ -77,6 +77,22 @@ vows.describe('simple optimizations') 'mixed': [ ' label ~ \n* + span , div>*.class, section\n\n{color:red}', [['div>.class'], ['label~*+span'], ['section']] + ], + 'escaped joining character #1': [ + '.class\\~ div{color: red}', + [['.class\\~ div']] + ], + 'escaped joining character #2': [ + '.class\\+\\+ div{color: red}', + [['.class\\+\\+ div']] + ], + 'escaped joining character #3': [ + '.class\\> \\~div{color: red}', + [['.class\\> \\~div']] + ], + 'escaped characters': [ + '.a\\+\\+b{color: red}', + [['.a\\+\\+b']] ] }) )