Skip to content

Commit 76123ec

Browse files
committed
Protect against libraries that extend Array.prototype
for (var ... in ...) loops should always check if the property being iterated isn't borrowed from somewhere else. In this particular case, the code breaks if used in the same environment as old versions of PrototypeJS.
1 parent 7e6da09 commit 76123ec

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

diffview.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ diffview = {
188188
node2.setAttribute("href", "http://github.com/cemerick/jsdifflib");
189189

190190
tdata.push(node = document.createElement("tbody"));
191-
for (var idx in rows) node.appendChild(rows[idx]);
191+
for (var idx in rows) rows.hasOwnProperty(idx) && node.appendChild(rows[idx]);
192192

193193
node = celt("table", "diff" + (inline ? " inlinediff" : ""));
194-
for (var idx in tdata) node.appendChild(tdata[idx]);
194+
for (var idx in tdata) tdata.hasOwnProperty(idx) && node.appendChild(tdata[idx]);
195195
return node;
196196
}
197-
}
197+
}

0 commit comments

Comments
 (0)