提交 be5e8d57 编写于 作者: A Alex Dima

Fixes #12122: Use Object.prototype.hasOwnProperty when building up the diff hash table

上级 db88c318
......@@ -211,6 +211,8 @@ class DiffChangeHelper {
}
const hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* An implementation of the difference algorithm described in
* "An O(ND) Difference Algorithm and its letiations" by Eugene W. Myers
......@@ -257,7 +259,7 @@ export class LcsDiff {
// Fill up the hash table for unique elements
for (i = 0; i < originalSequenceLength; i++) {
let originalElementHash = this.OriginalSequence.getElementHash(i);
if (!hashTable.hasOwnProperty(originalElementHash)) {
if (!hasOwnProperty.call(hashTable, originalElementHash)) {
// No entry in the hashtable so this is a new unique element.
// Assign the element a new unique identifier and add it to the
// hash table
......@@ -271,7 +273,7 @@ export class LcsDiff {
// Now match up modified elements
for (i = 0; i < modifiedSequenceLength; i++) {
let modifiedElementHash = this.ModifiedSequence.getElementHash(i);
if (!hashTable.hasOwnProperty(modifiedElementHash)) {
if (!hasOwnProperty.call(hashTable, modifiedElementHash)) {
this.m_modifiedIds[i] = currentUniqueId++;
hashTable[modifiedElementHash] = this.m_modifiedIds[i];
} else {
......
......@@ -394,4 +394,13 @@ suite('Editor Diff - DiffComputer', () => {
];
assertDiff(original, modified, expected, false, true);
});
test('issue #12122 r.hasOwnProperty is not a function', () => {
var original = [ 'hasOwnProperty' ];
var modified = [ 'hasOwnProperty', 'and another line' ];
var expected = [
createLineInsertion(2, 2, 1)
];
assertDiff(original, modified, expected);
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册