Skip to content

Commit c2f8fb9

Browse files
authored
Fix lineHash.hasOwnProperty might be contaminated
if calling method like dmp.diff_linesToChars_('hasOwnProperty', ' ') will throw TypeError: lineHash.hasOwnProperty is not a function since the lineHash is a instance of Object, the method can be overwritten while walking through the text lines. To avoid this, we can use Object.prototype.hasOwnProperty.call(lineHash, line) that make it always can call hasOwnProperty properly. Update diff_match_patch_uncompressed.js
1 parent 5b73bb8 commit c2f8fb9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) {
475475
var line = text.substring(lineStart, lineEnd + 1);
476476
lineStart = lineEnd + 1;
477477

478-
if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) :
478+
if (lineHash.hasOwnProperty ? Object.prototype.hasOwnProperty.call(lineHash, line) :
479479
(lineHash[line] !== undefined)) {
480480
chars += String.fromCharCode(lineHash[line]);
481481
} else {

0 commit comments

Comments
 (0)