mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Avoid using the values toString method in _.invert if it’s not a function. [closes #3260]
This commit is contained in:
10
lodash.js
10
lodash.js
@@ -13173,6 +13173,11 @@
|
|||||||
* // => { '1': 'c', '2': 'b' }
|
* // => { '1': 'c', '2': 'b' }
|
||||||
*/
|
*/
|
||||||
var invert = createInverter(function(result, value, key) {
|
var invert = createInverter(function(result, value, key) {
|
||||||
|
if (value != null &&
|
||||||
|
typeof value.toString != 'function') {
|
||||||
|
value = nativeObjectToString.call(value);
|
||||||
|
}
|
||||||
|
|
||||||
result[value] = key;
|
result[value] = key;
|
||||||
}, constant(identity));
|
}, constant(identity));
|
||||||
|
|
||||||
@@ -13203,6 +13208,11 @@
|
|||||||
* // => { 'group1': ['a', 'c'], 'group2': ['b'] }
|
* // => { 'group1': ['a', 'c'], 'group2': ['b'] }
|
||||||
*/
|
*/
|
||||||
var invertBy = createInverter(function(result, value, key) {
|
var invertBy = createInverter(function(result, value, key) {
|
||||||
|
if (value != null &&
|
||||||
|
typeof value.toString != 'function') {
|
||||||
|
value = nativeObjectToString.call(value);
|
||||||
|
}
|
||||||
|
|
||||||
if (hasOwnProperty.call(result, value)) {
|
if (hasOwnProperty.call(result, value)) {
|
||||||
result[value].push(key);
|
result[value].push(key);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user