From 01148a1df881b7b1f2cd92626bbdb330176ca1b1 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Wed, 12 Jul 2017 07:42:33 -0700 Subject: [PATCH] =?UTF-8?q?Avoid=20using=20the=20values=20toString=20metho?= =?UTF-8?q?d=20in=20=5F.invert=20if=20it=E2=80=99s=20not=20a=20function.?= =?UTF-8?q?=20[closes=20#3260]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- invert.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/invert.js b/invert.js index 3cb243054..1078a2534 100644 --- a/invert.js +++ b/invert.js @@ -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