From 83379fc3200fef0191b73448ee524eb141cc203e Mon Sep 17 00:00:00 2001 From: Max Wu Date: Wed, 24 Jun 2020 15:08:23 +0800 Subject: [PATCH] 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 --- javascript/diff_match_patch_uncompressed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/diff_match_patch_uncompressed.js b/javascript/diff_match_patch_uncompressed.js index 88a702c2..2d0f8480 100644 --- a/javascript/diff_match_patch_uncompressed.js +++ b/javascript/diff_match_patch_uncompressed.js @@ -495,7 +495,7 @@ diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) { } var line = text.substring(lineStart, lineEnd + 1); - if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) : + if (lineHash.hasOwnProperty ? Object.prototype.hasOwnProperty.call(lineHash, line) : (lineHash[line] !== undefined)) { chars += String.fromCharCode(lineHash[line]); } else {