Skip to content
This repository was archived by the owner on Aug 5, 2024. It is now read-only.

Commit 9da49a6

Browse files
committed
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 62f2e68 commit 9da49a6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

javascript/diff_match_patch_uncompressed.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
8+
89
* You may obtain a copy of the License at
910
*
1011
* http://www.apache.org/licenses/LICENSE-2.0
@@ -495,7 +496,7 @@ diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) {
495496
}
496497
var line = text.substring(lineStart, lineEnd + 1);
497498

498-
if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) :
499+
if (lineHash.hasOwnProperty ? Object.prototype.hasOwnProperty.call(lineHash, line) :
499500
(lineHash[line] !== undefined)) {
500501
chars += String.fromCharCode(lineHash[line]);
501502
} else {

0 commit comments

Comments
 (0)