From e8a2a5fc15e81fcd853f19decdcb4dd2f756a58a Mon Sep 17 00:00:00 2001 From: GoalSmashers Date: Fri, 27 Dec 2013 12:27:18 +0100 Subject: [PATCH] Fixes #198 - correctly handle a mixup of comments and @import statements. This is a follow up to #192 which apparently fixed an edge case of processing more than one @import inside a comment but introduced this issue. --- History.md | 1 + lib/imports/inliner.js | 5 +++-- test/data/issue-198-min.css | 3 +++ test/data/issue-198.css | 4 ++++ 4 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/data/issue-198-min.css create mode 100644 test/data/issue-198.css diff --git a/History.md b/History.md index d46fa502..2e1249cc 100644 --- a/History.md +++ b/History.md @@ -12,6 +12,7 @@ [2.0.6 / 2014-xx-xx (UNRELEASED)](https://github.com/GoalSmashers/clean-css/compare/v2.0.5...v2.0.6) ================== +* Fixed issue [#198](https://github.com/GoalSmashers/clean-css/issues/198) - process comments and `@import`s correctly. * 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) diff --git a/lib/imports/inliner.js b/lib/imports/inliner.js index f67ad59f..95bd13f6 100644 --- a/lib/imports/inliner.js +++ b/lib/imports/inliner.js @@ -44,6 +44,7 @@ module.exports = function Inliner(context) { var commentScanner = function(data) { var commentRegex = /(\/\*(?!\*\/)[\s\S]*?\*\/)/; + var lastStartIndex = 0; var lastEndIndex = 0; var noComments = false; @@ -60,7 +61,7 @@ module.exports = function Inliner(context) { return false; // idx can be still within last matched comment (many @import statements inside one comment) - if (idx < lastEndIndex) + if (idx > lastStartIndex && idx < lastEndIndex) return true; comment = data.match(commentRegex); @@ -71,7 +72,7 @@ module.exports = function Inliner(context) { } // get the indexes relative to the current data chunk - localStartIndex = comment.index; + lastStartIndex = localStartIndex = comment.index; localEndIndex = localStartIndex + comment[0].length; // calculate the indexes relative to the full original data diff --git a/test/data/issue-198-min.css b/test/data/issue-198-min.css new file mode 100644 index 00000000..78b32f50 --- /dev/null +++ b/test/data/issue-198-min.css @@ -0,0 +1,3 @@ +.one{color:red} +.three{background-image:url(partials/extra/down.gif)} +.imports-with-comment{color:#999} diff --git a/test/data/issue-198.css b/test/data/issue-198.css new file mode 100644 index 00000000..1ef29955 --- /dev/null +++ b/test/data/issue-198.css @@ -0,0 +1,4 @@ +@import url('./partials/one.css'); +@import url('./partials/three.css'); +/*some comment, you guys!*/ +.imports-with-comment { color: #999; } -- 2.34.1