From: Jakub Pawlowicz Date: Sun, 12 Oct 2014 15:14:38 +0000 (+0100) Subject: Fixes comments processor on non-*nix systems. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=a4e115dca14c9667dd2cf1b1898053a5faae71c6;p=clean-css.git Fixes comments processor on non-*nix systems. * Windows, I'm looking at you! --- diff --git a/lib/text/comments-processor.js b/lib/text/comments-processor.js index 1d856079..748bd072 100644 --- a/lib/text/comments-processor.js +++ b/lib/text/comments-processor.js @@ -84,10 +84,10 @@ CommentsProcessor.prototype.restore = function (data) { if (comment.indexOf(SPECIAL_COMMENT_PREFIX) === 0 && (this.keepAll || (this.keepOne && restored === 0))) { restored++; - addBreak = this.keepBreaks && data[nextMatch.end] != '\n' && data[nextMatch.end] != '\r\n'; + addBreak = this.keepBreaks && data[nextMatch.end] != '\n' && data.lastIndexOf('\r\n', nextMatch.end + 1) != nextMatch.end; tempData.push(comment, addBreak ? lineBreak : ''); } else { - nextMatch.end += this.keepBreaks ? 1 : 0; + nextMatch.end += this.keepBreaks ? lineBreak.length : 0; } cursor = nextMatch.end; diff --git a/test/text/comments-processor-test.js b/test/text/comments-processor-test.js index 92e6348c..877f2eaa 100644 --- a/test/text/comments-processor-test.js +++ b/test/text/comments-processor-test.js @@ -3,6 +3,7 @@ var assert = require('assert'); var CommentsProcessor = require('../../lib/text/comments-processor'); var lineBreak = require('os').EOL; +var otherLineBreak = lineBreak == '\n' ? '\r\n' : '\n'; function processorContext(name, context, keepSpecialComments, keepBreaks) { var vowContext = {}; @@ -136,6 +137,11 @@ vows.describe(CommentsProcessor) 'a{}/*! some text */' + lineBreak + 'p{}', 'a{}__ESCAPED_COMMENT_CLEAN_CSS0__' + lineBreak + 'p{}', 'a{}/*! some text */' + lineBreak + 'p{}' + ], + 'if given an other platform break already': [ + 'a{}/*! some text */' + otherLineBreak + 'p{}', + 'a{}__ESCAPED_COMMENT_CLEAN_CSS0__' + otherLineBreak + 'p{}', + 'a{}/*! some text */' + otherLineBreak + 'p{}' ] }, '1', true) )