mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Ensure _.isPlainObject returns false for objects without a [[Class]] of "Object".
Former-commit-id: ce034f55733cd1929f09bf80e4a461c6e1502d1b
This commit is contained in:
20
build.js
20
build.js
@@ -1090,6 +1090,13 @@
|
|||||||
return match.replace(/\s*\(support\.argsClass *\?([^:]+):.+?\)\)/g, '$1');
|
return match.replace(/\s*\(support\.argsClass *\?([^:]+):.+?\)\)/g, '$1');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// remove `support.argsClass` from `_.isPlainObject`
|
||||||
|
_.each(['shimIsPlainObject', 'isPlainObject'], function(methodName) {
|
||||||
|
source = source.replace(matchFunction(source, methodName), function(match) {
|
||||||
|
return match.replace(/\s*\|\|\s*\(!support\.argsClass[\s\S]+?\)\)/, '');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1114,7 +1121,7 @@
|
|||||||
source = source.replace(getIteratorTemplate(source), function(match) {
|
source = source.replace(getIteratorTemplate(source), function(match) {
|
||||||
return match
|
return match
|
||||||
.replace(/(?: *\/\/.*\n)* *["'] *(?:<% *)?if *\(support\.enumPrototypes *(?:&&|\))[\s\S]+?<% *} *(?:%>|["']).+/g, '')
|
.replace(/(?: *\/\/.*\n)* *["'] *(?:<% *)?if *\(support\.enumPrototypes *(?:&&|\))[\s\S]+?<% *} *(?:%>|["']).+/g, '')
|
||||||
.replace(/support\.enumPrototypes *\|\|\s*/g, '');
|
.replace(/support\.enumPrototypes\s*\|\|\s*/g, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
@@ -1137,12 +1144,12 @@
|
|||||||
|
|
||||||
// remove `support.nodeClass` from `_.clone`
|
// remove `support.nodeClass` from `_.clone`
|
||||||
source = source.replace(matchFunction(source, 'clone'), function(match) {
|
source = source.replace(matchFunction(source, 'clone'), function(match) {
|
||||||
return match.replace(/ *\|\|\s*\(!support\.nodeClass[\s\S]+?\)\)/, '');
|
return match.replace(/\s*\|\|\s*\(!support\.nodeClass[\s\S]+?\)\)/, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
// remove `support.nodeClass` from `_.isEqual`
|
// remove `support.nodeClass` from `_.isEqual`
|
||||||
source = source.replace(matchFunction(source, 'isEqual'), function(match) {
|
source = source.replace(matchFunction(source, 'isEqual'), function(match) {
|
||||||
return match.replace(/ *\|\|\s*\(!support\.nodeClass[\s\S]+?\)\)\)/, '');
|
return match.replace(/\s*\|\|\s*\(!support\.nodeClass[\s\S]+?\)\)\)/, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
@@ -1169,7 +1176,7 @@
|
|||||||
source = source.replace(getIteratorTemplate(source), function(match) {
|
source = source.replace(getIteratorTemplate(source), function(match) {
|
||||||
return match
|
return match
|
||||||
.replace(/(?: *\/\/.*\n)*( *["'] *)<% *} *else *if *\(support\.nonEnumArgs[\s\S]+?(\1<% *} *%>.+)/, '$2')
|
.replace(/(?: *\/\/.*\n)*( *["'] *)<% *} *else *if *\(support\.nonEnumArgs[\s\S]+?(\1<% *} *%>.+)/, '$2')
|
||||||
.replace(/ *\|\|\s*support\.nonEnumArgs/, '');
|
.replace(/\s*\|\|\s*support\.nonEnumArgs/, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
@@ -1710,6 +1717,7 @@
|
|||||||
if (isModern) {
|
if (isModern) {
|
||||||
dependencyMap.isEmpty = _.without(dependencyMap.isEmpty, 'isArguments');
|
dependencyMap.isEmpty = _.without(dependencyMap.isEmpty, 'isArguments');
|
||||||
dependencyMap.isEqual = _.without(dependencyMap.isEqual, 'isArguments');
|
dependencyMap.isEqual = _.without(dependencyMap.isEqual, 'isArguments');
|
||||||
|
dependencyMap.isPlainObject = _.without(dependencyMap.isPlainObject, 'isArguments');
|
||||||
dependencyMap.keys = _.without(dependencyMap.keys, 'isArguments');
|
dependencyMap.keys = _.without(dependencyMap.keys, 'isArguments');
|
||||||
dependencyMap.reduceRight = _.without(dependencyMap.reduceRight, 'isString');
|
dependencyMap.reduceRight = _.without(dependencyMap.reduceRight, 'isString');
|
||||||
}
|
}
|
||||||
@@ -2357,7 +2365,7 @@
|
|||||||
|
|
||||||
// remove native `Array.isArray` branch in `_.isArray`
|
// remove native `Array.isArray` branch in `_.isArray`
|
||||||
source = source.replace(matchFunction(source, 'isArray'), function(match) {
|
source = source.replace(matchFunction(source, 'isArray'), function(match) {
|
||||||
return match.replace(/nativeIsArray * \|\|\s*/, '');
|
return match.replace(/nativeIsArray\s*\|\|\s*/, '');
|
||||||
});
|
});
|
||||||
|
|
||||||
// replace `_.keys` with `shimKeys`
|
// replace `_.keys` with `shimKeys`
|
||||||
@@ -2509,7 +2517,7 @@
|
|||||||
|
|
||||||
// minor cleanup
|
// minor cleanup
|
||||||
snippet = snippet
|
snippet = snippet
|
||||||
.replace(/obj *\|\|\s*\(obj *= *{}\);/, '')
|
.replace(/obj\s*\|\|\s*\(obj *= *{}\);/, '')
|
||||||
.replace(/var __p = '';\s*__p \+=/, 'var __p =');
|
.replace(/var __p = '';\s*__p \+=/, 'var __p =');
|
||||||
|
|
||||||
// remove comments, including sourceURLs
|
// remove comments, including sourceURLs
|
||||||
|
|||||||
6
dist/lodash.compat.js
vendored
6
dist/lodash.compat.js
vendored
@@ -1005,7 +1005,7 @@
|
|||||||
function shimIsPlainObject(value) {
|
function shimIsPlainObject(value) {
|
||||||
// avoid non-objects and false positives for `arguments` objects
|
// avoid non-objects and false positives for `arguments` objects
|
||||||
var result = false;
|
var result = false;
|
||||||
if (!(value && typeof value == 'object') || isArguments(value)) {
|
if (!(value && toString.call(value) == objectClass) || (!support.argsClass && isArguments(value))) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// check that the constructor is `Object` (i.e. `Object instanceof Object`)
|
// check that the constructor is `Object` (i.e. `Object instanceof Object`)
|
||||||
@@ -1838,14 +1838,14 @@
|
|||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
|
var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
|
||||||
if (!(value && typeof value == 'object')) {
|
if (!(value && toString.call(value) == objectClass) || (!support.argsClass && isArguments(value))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var valueOf = value.valueOf,
|
var valueOf = value.valueOf,
|
||||||
objProto = typeof valueOf == 'function' && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
|
objProto = typeof valueOf == 'function' && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
|
||||||
|
|
||||||
return objProto
|
return objProto
|
||||||
? value == objProto || (getPrototypeOf(value) == objProto && !isArguments(value))
|
? (value == objProto || getPrototypeOf(value) == objProto)
|
||||||
: shimIsPlainObject(value);
|
: shimIsPlainObject(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
6
dist/lodash.js
vendored
6
dist/lodash.js
vendored
@@ -841,7 +841,7 @@
|
|||||||
function shimIsPlainObject(value) {
|
function shimIsPlainObject(value) {
|
||||||
// avoid non-objects and false positives for `arguments` objects
|
// avoid non-objects and false positives for `arguments` objects
|
||||||
var result = false;
|
var result = false;
|
||||||
if (!(value && typeof value == 'object') || isArguments(value)) {
|
if (!(value && toString.call(value) == objectClass)) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// check that the constructor is `Object` (i.e. `Object instanceof Object`)
|
// check that the constructor is `Object` (i.e. `Object instanceof Object`)
|
||||||
@@ -1657,14 +1657,14 @@
|
|||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
var isPlainObject = function(value) {
|
var isPlainObject = function(value) {
|
||||||
if (!(value && typeof value == 'object')) {
|
if (!(value && toString.call(value) == objectClass)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var valueOf = value.valueOf,
|
var valueOf = value.valueOf,
|
||||||
objProto = typeof valueOf == 'function' && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
|
objProto = typeof valueOf == 'function' && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
|
||||||
|
|
||||||
return objProto
|
return objProto
|
||||||
? value == objProto || (getPrototypeOf(value) == objProto && !isArguments(value))
|
? (value == objProto || getPrototypeOf(value) == objProto)
|
||||||
: shimIsPlainObject(value);
|
: shimIsPlainObject(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
2
dist/lodash.underscore.js
vendored
2
dist/lodash.underscore.js
vendored
@@ -656,7 +656,7 @@
|
|||||||
function shimIsPlainObject(value) {
|
function shimIsPlainObject(value) {
|
||||||
// avoid non-objects and false positives for `arguments` objects
|
// avoid non-objects and false positives for `arguments` objects
|
||||||
var result = false;
|
var result = false;
|
||||||
if (!(value && typeof value == 'object') || isArguments(value)) {
|
if (!(value && toString.call(value) == objectClass)) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// check that the constructor is `Object` (i.e. `Object instanceof Object`)
|
// check that the constructor is `Object` (i.e. `Object instanceof Object`)
|
||||||
|
|||||||
@@ -1016,7 +1016,7 @@
|
|||||||
function shimIsPlainObject(value) {
|
function shimIsPlainObject(value) {
|
||||||
// avoid non-objects and false positives for `arguments` objects
|
// avoid non-objects and false positives for `arguments` objects
|
||||||
var result = false;
|
var result = false;
|
||||||
if (!(value && typeof value == 'object') || isArguments(value)) {
|
if (!(value && toString.call(value) == objectClass) || (!support.argsClass && isArguments(value))) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// check that the constructor is `Object` (i.e. `Object instanceof Object`)
|
// check that the constructor is `Object` (i.e. `Object instanceof Object`)
|
||||||
@@ -1849,14 +1849,14 @@
|
|||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
|
var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) {
|
||||||
if (!(value && typeof value == 'object')) {
|
if (!(value && toString.call(value) == objectClass) || (!support.argsClass && isArguments(value))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var valueOf = value.valueOf,
|
var valueOf = value.valueOf,
|
||||||
objProto = typeof valueOf == 'function' && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
|
objProto = typeof valueOf == 'function' && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto);
|
||||||
|
|
||||||
return objProto
|
return objProto
|
||||||
? value == objProto || (getPrototypeOf(value) == objProto && !isArguments(value))
|
? (value == objProto || getPrototypeOf(value) == objProto)
|
||||||
: shimIsPlainObject(value);
|
: shimIsPlainObject(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1406,6 +1406,13 @@
|
|||||||
strictEqual(_.isPlainObject([1, 2, 3]), false);
|
strictEqual(_.isPlainObject([1, 2, 3]), false);
|
||||||
strictEqual(_.isPlainObject({ 'a': 1 }), true);
|
strictEqual(_.isPlainObject({ 'a': 1 }), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should return `false` for objects without a [[Class]] of "Object"', function() {
|
||||||
|
strictEqual(_.isPlainObject(arguments), false);
|
||||||
|
strictEqual(_.isPlainObject(Error), false);
|
||||||
|
strictEqual(_.isPlainObject(Math), false);
|
||||||
|
strictEqual(_.isPlainObject(window), false);
|
||||||
|
})
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user