mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47: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`.
|
||||
* If `object` contains duplicate values, subsequent values overwrite
|
||||
@@ -17,6 +19,9 @@
|
||||
function invert(object) {
|
||||
const result = {}
|
||||
Object.keys(object).forEach((value, key) => {
|
||||
if (value != null && typeof value.toString != 'function') {
|
||||
value = toString.call(value)
|
||||
}
|
||||
result[value] = key
|
||||
})
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user