From 26180dbf0da730f8091e4de2b399871d4b49d929 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Sun, 1 Mar 2015 17:56:57 +0000 Subject: [PATCH] Fixes #466 - rebuilding background shorthand. In case of multi-value shorthands (comma separated) we reuse tokens instead of cloning when splitting / rebuilding values. There was an edge case in rebuilding when having more than one `background` in a rule. --- History.md | 1 + lib/properties/processable.js | 3 +++ test/fixtures/issue-466-min.css | 1 + test/fixtures/issue-466.css | 4 ++++ 4 files changed, 9 insertions(+) create mode 100644 test/fixtures/issue-466-min.css create mode 100644 test/fixtures/issue-466.css diff --git a/History.md b/History.md index 414159f4..a34d1497 100644 --- a/History.md +++ b/History.md @@ -7,6 +7,7 @@ ================== * Refixed issue [#471](https://github.com/jakubpawlowicz/clean-css/issues/471) - correct order after restructuring. +* Fixes issue [#466](https://github.com/jakubpawlowicz/clean-css/issues/466) - rebuilding background shorthand. * Fixes issue [#462](https://github.com/jakubpawlowicz/clean-css/issues/462) - escaped apostrophes in selectors. [3.1.1 / 2015-02-27](https://github.com/jakubpawlowicz/clean-css/compare/v3.1.0...v3.1.1) diff --git a/lib/properties/processable.js b/lib/properties/processable.js index f27e7916..ea30c79b 100644 --- a/lib/properties/processable.js +++ b/lib/properties/processable.js @@ -147,11 +147,14 @@ module.exports = (function () { var values = new Splitter(',').split(token.value); var components = []; + // TODO: we should be rather clonging elements than reusing them! for (var i = 0, l = values.length; i < l; i++) { token.value = values[i]; components.push(splitfunc(token)); } + token.value = values.join(','); + for (var j = 0, m = components[0].length; j < m; j++) { for (var k = 0, n = components.length, newValues = []; k < n; k++) { newValues.push(components[k][j].value); diff --git a/test/fixtures/issue-466-min.css b/test/fixtures/issue-466-min.css new file mode 100644 index 00000000..c4bc93e2 --- /dev/null +++ b/test/fixtures/issue-466-min.css @@ -0,0 +1 @@ +div{background:url(image.png);background:linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.5)),url(image.png)} diff --git a/test/fixtures/issue-466.css b/test/fixtures/issue-466.css new file mode 100644 index 00000000..5e2ca82b --- /dev/null +++ b/test/fixtures/issue-466.css @@ -0,0 +1,4 @@ +div { + background: url(image.png); + background-image: linear-gradient(rgba(0,0,0,.1), rgba(0,0,0,.5)), url(image.png); +} -- 2.34.1