From bf1ec3379f08c65c0b155c3f31df98ffcb25b13d Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Sun, 11 Jan 2015 10:26:13 +0000 Subject: [PATCH] Fixes #314 - handling spaces inside calc expressions. --- History.md | 7 ++++++- lib/utils/extractors.js | 5 ++++- test/integration-test.js | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/History.md b/History.md index 38b1e8db..2c5689c3 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,4 @@ -[3.1.0 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.3...v3.1.0) +[3.1.0 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.4...v3.1.0) ================== * Adds 0deg to 0 minification where possible. @@ -7,6 +7,11 @@ * Fixed issue [#182](https://github.com/GoalSmashers/clean-css/issues/182) - removing space after closing brace. * Fixed issue [#357](https://github.com/GoalSmashers/clean-css/issues/357) - non-standard but valid URLs. +[3.0.4 / 2015-xx-xx](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.3...v3.0.4) +================== + +* Fixed issue [#314](https://github.com/GoalSmashers/clean-css/issues/314) - spaces inside calc. + [3.0.3 / 2015-01-07](https://github.com/jakubpawlowicz/clean-css/compare/v3.0.2...v3.0.3) ================== diff --git a/lib/utils/extractors.js b/lib/utils/extractors.js index de4f5446..d8b4c47a 100644 --- a/lib/utils/extractors.js +++ b/lib/utils/extractors.js @@ -14,6 +14,7 @@ var Extractors = { var isSpecial; var wasSpecial; var current; + var secondToLast; var wasCloseParenthesis; var isEscape; var token; @@ -63,7 +64,9 @@ var Extractors = { isSpecial = current === ':' || current === '[' || current === ']' || current === ',' || current === '(' || current === ')'; if (wasWhitespace && isSpecial) { - buffer.pop(); + secondToLast = buffer[buffer.length - 2]; + if (secondToLast != '+' && secondToLast != '-' && secondToLast != '/' && secondToLast != '*') + buffer.pop(); buffer.push(current); } else if (isWhitespace && wasSpecial && !wasCloseParenthesis) { } else if (isWhitespace && !wasWhitespace && buffer.length > 0) { diff --git a/test/integration-test.js b/test/integration-test.js index ea779bf1..4ff1be13 100644 --- a/test/integration-test.js +++ b/test/integration-test.js @@ -132,6 +132,10 @@ vows.describe('integration tests').addBatch({ 'div{height:-moz-calc(3 * 2em + 10px)}', 'div{height:-moz-calc(3 * 2em + 10px)}' ], + 'not inside calc method with brackets': [ + 'body{margin-left:calc(50vw + (1024px/2))}', + 'body{margin-left:calc(50vw + (1024px/2))}' + ], 'before colon': [ '#test{padding-left :0}', '#test{padding-left:0}' -- 2.34.1