Add keyPrefix to avoid issues with __proto__. [closes #226]

Former-commit-id: 55dee782acdd5e28229b1fcb7587424d3fdfd445
This commit is contained in:
John-David Dalton
2013-04-01 21:54:42 -07:00
parent 80a39393fe
commit 6c25905ae4
2 changed files with 42 additions and 11 deletions

View File

@@ -1074,6 +1074,36 @@
/*--------------------------------------------------------------------------*/
QUnit.module('`__proto__` property bugs');
(function() {
var stringLiteral = '__proto__',
stringObject = Object(stringLiteral),
expected = [stringLiteral, stringObject];
var array = _.times(100, function(count) {
return count % 2 ? stringObject : stringLiteral;
});
test('internal data objects should work with the `__proto__` key', function() {
deepEqual(_.difference(array, array), []);
deepEqual(_.intersection(array, array), expected);
deepEqual(_.uniq(array), expected);
deepEqual(_.without.apply(_, [array].concat(array)), []);
});
test('lodash.memoize should memoize values resolved to the `__proto__` key', function() {
var count = 0,
memoized = _.memoize(function() { return ++count; });
memoized('__proto__');
memoized('__proto__');
strictEqual(count, 1);
});
}());
/*--------------------------------------------------------------------------*/
QUnit.module('lodash.groupBy');
(function() {