Fixes comments processor on non-*nix systems.
authorJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 12 Oct 2014 15:14:38 +0000 (16:14 +0100)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Sun, 12 Oct 2014 15:14:38 +0000 (16:14 +0100)
* Windows, I'm looking at you!

lib/text/comments-processor.js
test/text/comments-processor-test.js

index 1d85607..748bd07 100644 (file)
@@ -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;
index 92e6348..877f2ea 100644 (file)
@@ -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)
   )