mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Avoid using the values toString method in _.invert if it’s not a function. [closes #3260]
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
const toString = Object.prototype.toString
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an object composed of the inverted keys and values of `object`.
|
* Creates an object composed of the inverted keys and values of `object`.
|
||||||
* If `object` contains duplicate values, subsequent values overwrite
|
* If `object` contains duplicate values, subsequent values overwrite
|
||||||
@@ -17,6 +19,9 @@
|
|||||||
function invert(object) {
|
function invert(object) {
|
||||||
const result = {}
|
const result = {}
|
||||||
Object.keys(object).forEach((value, key) => {
|
Object.keys(object).forEach((value, key) => {
|
||||||
|
if (value != null && typeof value.toString != 'function') {
|
||||||
|
value = toString.call(value)
|
||||||
|
}
|
||||||
result[value] = key
|
result[value] = key
|
||||||
})
|
})
|
||||||
return result
|
return result
|
||||||
|
|||||||
Reference in New Issue
Block a user