Skip to content

Commit 8ed1286

Browse files
committed
Merge pull request #320 from dgreensp/master
Fix #310 - diff highlighter breaks on some strings
2 parents 4ce6f02 + 71ecaaa commit 8ed1286

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

html/lib/diffHighlighter.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,24 +465,28 @@ var inlinediff = (function () {
465465
];
466466
}
467467

468+
function hasProp(obj, x) {
469+
return Object.prototype.hasOwnProperty.call(obj, x);
470+
}
471+
468472
function diff( o, n ) {
469473
var ns = new Object();
470474
var os = new Object();
471475

472476
for ( var i = 0; i < n.length; i++ ) {
473-
if ( ns[ n[i] ] == null )
477+
if ( ! hasProp(ns, n[i]) )
474478
ns[ n[i] ] = { rows: new Array(), o: null };
475479
ns[ n[i] ].rows.push( i );
476480
}
477481

478482
for ( var i = 0; i < o.length; i++ ) {
479-
if ( os[ o[i] ] == null )
483+
if ( ! hasProp(os, o[i]) )
480484
os[ o[i] ] = { rows: new Array(), n: null };
481485
os[ o[i] ].rows.push( i );
482486
}
483487

484488
for ( var i in ns ) {
485-
if ( ns[i].rows.length == 1 && typeof(os[i]) != "undefined" && os[i].rows.length == 1 ) {
489+
if ( ns[i].rows.length == 1 && hasProp(os, i) && os[i].rows.length == 1 ) {
486490
n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] };
487491
o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] };
488492
}

0 commit comments

Comments
 (0)