mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
Fix #1707 hasOwnProperty usage
If hasOwnProperty is overridden, then calling `obj.hasOwnProperty(prop)` can fail. Any time a dictionary of user-generated items is built, we cannot rely on hasOwnProperty being safe, so must call it from the Object.prototype explicitly.
This commit is contained in:
@@ -25,7 +25,10 @@ var QueryString = exports;
|
||||
var urlDecode = process.binding('http_parser').urlDecode;
|
||||
|
||||
|
||||
function hOP(obj, prop) {
|
||||
// If obj.hasOwnProperty has been overridden, then calling
|
||||
// obj.hasOwnProperty(prop) will break.
|
||||
// See: https://github.com/joyent/node/issues/1707
|
||||
function hasOwnProperty(obj, prop) {
|
||||
return Object.prototype.hasOwnProperty.call(obj, prop);
|
||||
}
|
||||
|
||||
@@ -171,7 +174,7 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq) {
|
||||
var k = QueryString.unescape(x[0], true);
|
||||
var v = QueryString.unescape(x.slice(1).join(eq), true);
|
||||
|
||||
if (!hOP(obj, k)) {
|
||||
if (!hasOwnProperty(obj, k)) {
|
||||
obj[k] = v;
|
||||
} else if (!Array.isArray(obj[k])) {
|
||||
obj[k] = [obj[k], v];
|
||||
|
||||
Reference in New Issue
Block a user