diff --git a/diff.js b/diff.js
index a34c22a0..efab725e 100644
--- a/diff.js
+++ b/diff.js
@@ -165,7 +165,20 @@ var JsDiff = (function() {
var LineDiff = new Diff();
LineDiff.tokenize = function(value) {
- return value.split(/^/m);
+ var retLines = [];
+ var lines = value.split(/^/m);
+
+ for(var i = 0; i < lines.length; i++) {
+ var line = lines[i];
+ var lastLine = lines[i - 1];
+
+ if(line == '\n' && lastLine && lastLine.indexOf('\r') == lastLine.length - 1)
+ retLines[retLines.length - 1] += '\n';
+ else if(line)
+ retLines.push(line);
+ }
+
+ return retLines;
};
return {
diff --git a/test/diffTest.js b/test/diffTest.js
index 91dafe1c..e2aa8eab 100644
--- a/test/diffTest.js
+++ b/test/diffTest.js
@@ -103,6 +103,13 @@ describe('#diffLines', function() {
'line\nvalue\nline');
diff.convertChangesToXML(diffResult).should.equal('line\nvalue\nvalue \nline');
});
+
+ it('should handle windows line endings', function() {
+ var diffResult = diff.diffLines(
+ 'line\r\nold value \r\nline',
+ 'line\r\nnew value\r\nline');
+ diff.convertChangesToXML(diffResult).should.equal('line\r\nnew value\r\nold value \r\nline');
+ });
});
describe('convertToDMP', function() {