diff --git a/diff.js b/diff.js index 8f9426fa..2d42039e 100644 --- a/diff.js +++ b/diff.js @@ -270,13 +270,8 @@ lastLineLastChar = lastLine ? lastLine[lastLine.length - 1] : ''; // Merge lines that may contain windows new lines - if (line === '\n' && (lastLineLastChar === '\r' || lastLineLastChar === '\n')) { - if (this.ignoreTrim || lastLineLastChar === '\n'){ - //to avoid merging to \n\n, remove \n and add \r\n. + if (line === '\n' && lastLineLastChar === '\r') { retLines[retLines.length - 1] = retLines[retLines.length - 1].slice(0,-1) + '\r\n'; - } else { - retLines[retLines.length - 1] += '\n'; - } } else if (line) { if (this.ignoreTrim) { line = line.trim(); diff --git a/test/diffTest.js b/test/diffTest.js index f52d2852..ba02eacb 100644 --- a/test/diffTest.js +++ b/test/diffTest.js @@ -198,6 +198,13 @@ describe('#diffLines', function() { 'line\r\nnew value\r\nline'); diff.convertChangesToXML(diffResult).should.equal('line\r\nnew value\r\nold value \r\nline'); }); + + it('should handle empty lines', function() { + var diffResult = diff.diffLines( + 'line\n\nold value \n\nline', + 'line\n\nnew value\n\nline'); + diff.convertChangesToXML(diffResult).should.equal('line\n\nnew value\nold value \n\nline'); + }); }); // Trimmed Line Diff