8000 Avoid using the values toString method in _.invert if it’s not a func… · lodash/lodash@a73b92b · GitHub
[go: up one dir, main page]

Skip to content

Commit a73b92b

Browse files
committed
Avoid using the values toString method in _.invert if it’s not a function. [closes #3260]
1 parent
8000
 a1b5305 commit a73b92b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lodash.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13173,6 +13173,11 @@
1317313173
* // => { '1': 'c', '2': 'b' }
1317413174
*/
1317513175
var invert = createInverter(function(result, value, key) {
13176+
if (value != null &&
13177+
typeof value.toString != 'function') {
13178+
value = nativeObjectToString.call(value);
13179+
}
13180+
1317613181
result[value] = key;
1317713182
}, constant(identity));
1317813183

@@ -13203,6 +13208,11 @@
1320313208
* // => { 'group1': ['a', 'c'], 'group2': ['b'] }
1320413209
*/
1320513210
var invertBy = createInverter(function(result, value, key) {
13211+
if (value != null &&
13212+
typeof value.toString != 'function') {
13213+
value = nativeObjectToString.call(value);
13214+
}
13215+
1320613216
if (hasOwnProperty.call(result, value)) {
1320713217
result[value].push(key);
1320813218
} else {

0 commit comments

Comments
 (0)
0