Fixes #739 - error when a closing brace is missing.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Fri, 30 Dec 2016 11:49:02 +0000 (12:49 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Fri, 30 Dec 2016 11:49:02 +0000 (12:49 +0100)
Why:

* When such content gets parsed into a block we should ignore
  the whole declaration as browsers do.

History.md
lib/optimizer/basic.js
test/optimizer/basic-test.js
test/tokenizer/tokenize-test.js

index b882244..2ddfe31 100644 (file)
@@ -15,6 +15,7 @@
 * Fixed issue [#685](https://github.com/jakubpawlowicz/clean-css/issues/685) - adds lowercasing hex colors optimization.
 * Fixed issue [#686](https://github.com/jakubpawlowicz/clean-css/issues/686) - adds rounding precision for all units.
 * Fixed issue [#703](https://github.com/jakubpawlowicz/clean-css/issues/703) - changes default IE compatibility to 10+.
+* Fixed issue [#739](https://github.com/jakubpawlowicz/clean-css/issues/739) - error when a closing brace is missing.
 * Fixed issue [#756](https://github.com/jakubpawlowicz/clean-css/issues/756) - adds disabling font-weight optimizations.
 * Fixed issue [#758](https://github.com/jakubpawlowicz/clean-css/issues/758) - ignores rules with empty selector.
 * Fixed issue [#767](https://github.com/jakubpawlowicz/clean-css/issues/767) - disables remote `@import` inlining by default.
index 96ec441..f06bbec 100644 (file)
@@ -353,7 +353,7 @@ function removeQuotes(name, value) {
 
 function optimizeBody(properties, context) {
   var options = context.options;
-  var property, name, value;
+  var property, name, type, value;
   var valueIsUrl;
   var propertyToken;
   var _properties = wrapForOptimizing(properties);
@@ -393,9 +393,16 @@ function optimizeBody(properties, context) {
     }
 
     for (var j = 0, m = property.value.length; j < m; j++) {
+      type = property.value[j][0];
       value = property.value[j][1];
       valueIsUrl = isUrl(value);
 
+      if (type == Token.PROPERTY_BLOCK) {
+        property.unused = true;
+        context.warnings.push('Invalid value token at ' + formatPosition(value[0][1][2][0]) + '. Ignoring.');
+        break;
+      }
+
       if (valueIsUrl && !context.validator.isValidUrl(value)) {
         property.unused = true;
         context.warnings.push('Broken URL \'' + value + '\' at ' + formatPosition(property.value[j][2][0]) + '. Ignoring.');
index f4318e2..6c95da4 100644 (file)
@@ -116,6 +116,10 @@ vows.describe('simple optimizations')
       'invalid characters #3 - relation at the beginning': [
         '>.funky{background:red}',
         ''
+      ],
+      'missing semicolon and brace in the middle': [
+        'body{color:red a{color:blue;}',
+        ''
       ]
     }, { advanced: false })
   )
index 292a246..152926a 100644 (file)
@@ -3412,6 +3412,65 @@ vows.describe(tokenize)
           ]
         ]
       ],
+      'missing end brace and semicolon in the middle': [
+        'body{color:red a{color:blue;}',
+        [
+          [
+            'rule',
+            [
+              [
+                'rule-scope',
+                'body',
+                [
+                  [1, 0, undefined]
+                ]
+              ]
+            ],
+            [
+              [
+                'property',
+                [
+                  'property-name',
+                  'color',
+                  [
+                    [1, 5, undefined]
+                  ]
+                ],
+                [
+                  'property-value',
+                  'red',
+                  [
+                    [1, 11, undefined]
+                  ]
+                ],
+                [
+                  'property-block',
+                  [
+                    [
+                      'property',
+                      [
+                        'property-name',
+                        'acolor',
+                        [
+                          [1, 15, undefined]
+                        ]
+                      ],
+                      [
+                        'property-value',
+                        'blue',
+                        [
+                          [1, 23, undefined]
+                        ]
+
+                      ]
+                    ]
+                  ]
+                ]
+              ]
+            ]
+          ]
+        ]
+      ],
       'extra end brace in the middle': [
         'body{color:red}}a{color:blue;}',
         [