Skip to content

Commit

Permalink
Avoid using the values toString method in _.invert if it’s not a func…
Browse files Browse the repository at this point in the history
…tion. [closes #3260]
  • Loading branch information
jdalton committed Feb 4, 2018
1 parent a1b5305 commit a73b92b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lodash.js
Original file line number Diff line number Diff line change
Expand Up @@ -13173,6 +13173,11 @@
* // => { '1': 'c', '2': 'b' }
*/
var invert = createInverter(function(result, value, key) {
if (value != null &&
typeof value.toString != 'function') {
value = nativeObjectToString.call(value);
}

result[value] = key;
}, constant(identity));

Expand Down Expand Up @@ -13203,6 +13208,11 @@
* // => { 'group1': ['a', 'c'], 'group2': ['b'] }
*/
var invertBy = createInverter(function(result, value, key) {
if (value != null &&
typeof value.toString != 'function') {
value = nativeObjectToString.call(value);
}

if (hasOwnProperty.call(result, value)) {
result[value].push(key);
} else {
Expand Down

0 comments on commit a73b92b

Please sign in to comment.