Fixes #205 - freeze on broken @import declaration.
authorGoalSmashers <jakub@goalsmashers.com>
Fri, 3 Jan 2014 14:58:38 +0000 (15:58 +0100)
committerGoalSmashers <jakub@goalsmashers.com>
Sat, 4 Jan 2014 16:03:15 +0000 (17:03 +0100)
@import declarations without trailing semicolon led to an infinite loop in tokenizer.

History.md
lib/imports/inliner.js
test/unit-test.js

index ba63b4f..d46fa50 100644 (file)
@@ -9,6 +9,11 @@
 * Fixed issue [#165](https://github.com/GoalSmashers/clean-css/issues/165) - extra space after trailing parenthesis.
 * Fixed issue [#186](https://github.com/GoalSmashers/clean-css/issues/186) - strip unit from 0rem.
 
+[2.0.6 / 2014-xx-xx (UNRELEASED)](https://github.com/GoalSmashers/clean-css/compare/v2.0.5...v2.0.6)
+==================
+
+* Fixed issue [#205](https://github.com/GoalSmashers/clean-css/issues/205) - freeze on broken @import declaration.
+
 [2.0.5 / 2014-01-03](https://github.com/GoalSmashers/clean-css/compare/v2.0.4...v2.0.5)
 ==================
 
index e1e359a..f67ad59 100644 (file)
@@ -26,8 +26,11 @@ module.exports = function Inliner(context) {
       }
 
       nextEnd = data.indexOf(';', nextStart);
-      if (nextEnd == -1)
+      if (nextEnd == -1) {
+        tempData.push('');
+        cursor = data.length;
         break;
+      }
 
       tempData.push(data.substring(cursor, nextStart));
       tempData.push(inlinedFile(data, nextStart, nextEnd, options));
index a31ae7b..66d18f1 100644 (file)
@@ -1011,6 +1011,10 @@ title']{display:block}",
       "@import url('fake.css');",
       ''
     ],
+    'of an unknown file with a missing trailing semicolon': [
+      "@import url(fake.css)",
+      ''
+    ],
     'of a http file': "@import url(http://pro.goalsmashers.com/test.css);",
     'of a https file': [
       "@import url('https://pro.goalsmashers.com/test.css');",
@@ -1070,6 +1074,14 @@ title']{display:block}",
       '@import \'test/data/partials/one.css\' screen and (orientation:landscape);',
       "@media screen and (orientation:landscape){.one{color:red}}"
     ],
+    'of a real file with a missing trailing semicolon': [
+      "@import url(test/data/partials/one.css)",
+      ''
+    ],
+    'of a real files with a missing trailing semicolon': [
+      "@import url(test/data/partials/one.css)@import url(test/data/partials/two.css)",
+      ''
+    ],
     'of more files': [
       "@import url(test/data/partials/one.css);\n\na{display:block}\n\n@import url(test/data/partials/extra/three.css);",
       ".one{color:red}a{display:block}.three{color:#0f0}"