Fixes #304 - background position merging.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sat, 13 Dec 2014 10:42:56 +0000 (10:42 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sat, 13 Dec 2014 10:42:56 +0000 (10:42 +0000)
* Background positions with more than 2 components were treated incorrectly.

History.md
lib/properties/processable.js
test/data/issue-304-2-min.css [new file with mode: 0644]
test/data/issue-304-2.css [new file with mode: 0644]
test/integration-test.js

index 0953d74..9ce19b3 100644 (file)
@@ -24,6 +24,7 @@
 * Fixed issue [#373](https://github.com/GoalSmashers/clean-css/issues/373) - proper background shorthand merging.
 * Fixed issue [#395](https://github.com/GoalSmashers/clean-css/issues/395) - unescaped brackets in data URIs.
 * Fixed issue [#403](https://github.com/GoalSmashers/clean-css/issues/403) - tracking input files in source maps.
+* Refixed issue [#304](https://github.com/GoalSmashers/clean-css/issues/304) - background position merging.
 
 [2.2.19 / 2014-11-20](https://github.com/jakubpawlowicz/clean-css/compare/v2.2.18...v2.2.19)
 ==================
index 913108a..c1e256e 100644 (file)
@@ -172,6 +172,7 @@ module.exports = (function () {
     var repeat = result[3];
     var attachment = result[4];
     var color = result[5];
+    var positionSet = false;
 
     // Take care of inherit
     if (token.value === 'inherit') {
@@ -206,14 +207,13 @@ module.exports = (function () {
             i -= 2;
           } else if (parts[i - 1] == '/') {
             size.value = currentPart;
-            position.value = previousPart;
-            i--;
           } else {
-            position.value = previousPart + ' ' + currentPart;
-            i--;
+            position.value = currentPart + (positionSet ? ' ' + position.value : '');
+            positionSet = true;
           }
         } else {
-          position.value = currentPart;
+          position.value = currentPart + (positionSet ? ' ' + position.value : '');
+          positionSet = true;
         }
       } else if (validator.isValidBackgroundPositionAndSize(currentPart)) {
         var sizeValue = new Splitter('/').split(currentPart);
diff --git a/test/data/issue-304-2-min.css b/test/data/issue-304-2-min.css
new file mode 100644 (file)
index 0000000..919eb5b
--- /dev/null
@@ -0,0 +1,2 @@
+.one{background:url(one.png) right 10px top 10px no-repeat,linear-gradient(0deg,#efefef 0,#fff 100%)}
+.two{background:url(two.png) right 9px top 15px/9px 7px no-repeat,linear-gradient(-179deg,#FFF 0,#F9F9F9 100%)}
diff --git a/test/data/issue-304-2.css b/test/data/issue-304-2.css
new file mode 100644 (file)
index 0000000..02f068c
--- /dev/null
@@ -0,0 +1,6 @@
+.one {
+  background: url(one.png) no-repeat right 10px top 10px, linear-gradient(0deg, #efefef 0%, #ffffff 100%);
+}
+.two {
+  background: url(two.png) no-repeat right 9px top 15px/9px 7px, linear-gradient(-179deg, #FFFFFF 0%, #F9F9F9 100%);
+}
index 8f358f1..4993ed6 100644 (file)
@@ -2191,8 +2191,8 @@ title']{display:block}",
     ]
   }),
   'background size with -properties.backgroundSizeMerging': cssContext({
-    'standard': 'div{background:url(image.png) no-repeat center;background-size:cover}',
-    'prefix': 'div{-webkit-background:url(image.png) no-repeat center;-webkit-background-size:cover}'
+    'standard': 'div{background:url(image.png) center no-repeat;background-size:cover}',
+    'prefix': 'div{-webkit-background:url(image.png) center no-repeat;-webkit-background-size:cover}'
   }, { compatibility: '-properties.backgroundSizeMerging' }),
   'multiple backgrounds': cssContext({
     'should not produce longer values': 'p{background:no-repeat;background-position:100% 0,0 100%,100% 100%,50% 50%}'