Skip to content

Commit 2c4b647

Browse files
committed
Merge pull request #52 from felicienfrancois/master
Fix for #51 Wrong result of JsDiff.diffLines
2 parents b7f143c + 824c365 commit 2c4b647

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Diff for: diff.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,8 @@
270270
lastLineLastChar = lastLine ? lastLine[lastLine.length - 1] : '';
271271

272272
// Merge lines that may contain windows new lines
273-
if (line === '\n' && (lastLineLastChar === '\r' || lastLineLastChar === '\n')) {
274-
if (this.ignoreTrim || lastLineLastChar === '\n'){
275-
//to avoid merging to \n\n, remove \n and add \r\n.
273+
if (line === '\n' && lastLineLastChar === '\r') {
276274
retLines[retLines.length - 1] = retLines[retLines.length - 1].slice(0,-1) + '\r\n';
277-
} else {
278-
retLines[retLines.length - 1] += '\n';
279-
}
280275
} else if (line) {
281276
if (this.ignoreTrim) {
282277
line = line.trim();

Diff for: test/diffTest.js

+7
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ describe('#diffLines', function() {
198198
'line\r\nnew value\r\nline');
199199
diff.convertChangesToXML(diffResult).should.equal('line\r\n<ins>new value\r\n</ins><del>old value \r\n</del>line');
200200
});
201+
202+
it('should handle empty lines', function() {
203+
var diffResult = diff.diffLines(
204+
'line\n\nold value \n\nline',
205+
'line\n\nnew value\n\nline');
206+
diff.convertChangesToXML(diffResult).should.equal('line\n\n<ins>new value\n</ins><del>old value \n</del>\nline');
207+
});
201208
});
202209

203210
// Trimmed Line Diff

0 commit comments

Comments
 (0)