From 219762e7439ffc74ed1d7c1b8ab882ceeb269298 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowicz Date: Sun, 3 May 2015 15:03:33 +0100 Subject: [PATCH] Fixes #553 - another style of SVG fallback. This addresses any version of SVG fallback when one layer is set to none. It's not future proof though since: * it may bo none + sth * it may be an empty linear gradient Once we have #407 in place we'll be able to actually see which URL is a SVG and decide based on that. --- History.md | 1 + lib/properties/override-compactor.js | 30 ++++++++++++++++++++- test/properties/override-compacting-test.js | 11 +++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/History.md b/History.md index 91b345be..1d1f45e0 100644 --- a/History.md +++ b/History.md @@ -13,6 +13,7 @@ ================== * Fixed issue [#551](https://github.com/jakubpawlowicz/clean-css/issues/551) - edge case in restructuring. +* Fixed issue [#553](https://github.com/jakubpawlowicz/clean-css/issues/553) - another style of SVG fallback. * Fixed issue [#558](https://github.com/jakubpawlowicz/clean-css/issues/558) - units in same selector merging. [3.2.6 / 2015-04-28](https://github.com/jakubpawlowicz/clean-css/compare/v3.2.5...v3.2.6) diff --git a/lib/properties/override-compactor.js b/lib/properties/override-compactor.js index 7799f96c..5811dd3a 100644 --- a/lib/properties/override-compactor.js +++ b/lib/properties/override-compactor.js @@ -183,7 +183,35 @@ function noneOverrideHack(left, right) { (left.name == 'background' || left.name == 'background-image') && right.multiplex && (right.name == 'background' || right.name == 'background-image') && - right.value[right.value.length - 1][0] == 'none'; + anyLayerIsNone(right.value); +} + +function anyLayerIsNone(values) { + var layers = intoLayers(values); + + for (var i = 0, l = layers.length; i < l; i++) { + if (layers[i].length == 1 && layers[i][0][0] == 'none') + return true; + } + + return false; +} + +function intoLayers(values) { + var layers = []; + + for (var i = 0, layer = [], l = values.length; i < l; i++) { + var value = values[i]; + if (value[0] == MULTIPLEX_SEPARATOR) { + layers.push(layer); + layer = []; + } else { + layer.push(value); + } + } + + layers.push(layer); + return layers; } function compactOverrides(properties, compatibility, validator) { diff --git a/test/properties/override-compacting-test.js b/test/properties/override-compacting-test.js index 6266a295..b90bea86 100644 --- a/test/properties/override-compacting-test.js +++ b/test/properties/override-compacting-test.js @@ -524,7 +524,7 @@ vows.describe(optimize) } }, 'background then background - svg hack': { - 'topic': 'p{background:__ESCAPED_URL_CLEAN_CSS0__;background: __ESCAPED_URL_CLEAN_CSS1__,none}', + 'topic': 'p{background:__ESCAPED_URL_CLEAN_CSS0__;background:__ESCAPED_URL_CLEAN_CSS1__,none}', 'into': function (topic) { assert.deepEqual(_optimize(topic), [ [['background', false , false], ['__ESCAPED_URL_CLEAN_CSS0__']], @@ -532,6 +532,15 @@ vows.describe(optimize) ]); } }, + 'background then background - inverted svg hack': { + 'topic': 'p{background:__ESCAPED_URL_CLEAN_CSS0__;background:none,__ESCAPED_URL_CLEAN_CSS1__}', + 'into': function (topic) { + assert.deepEqual(_optimize(topic), [ + [['background', false , false], ['__ESCAPED_URL_CLEAN_CSS0__']], + [['background', false , false], ['0 0'], [','], ['__ESCAPED_URL_CLEAN_CSS1__']] + ]); + } + }, 'background-image then background-image - svg hack': { 'topic': 'p{background-image:__ESCAPED_URL_CLEAN_CSS0__;background-image: __ESCAPED_URL_CLEAN_CSS1__,none}', 'into': function (topic) { -- 2.34.1