From e02ce1ea8b444a4e7d2ffd33b5f218773f663a55 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 4 Mar 2016 08:09:39 -0800 Subject: [PATCH] Ensure `_.toPath` works with symbols. --- lodash.js | 5 ++++- test/test.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lodash.js b/lodash.js index 5f00dc612..10cee4c3f 100644 --- a/lodash.js +++ b/lodash.js @@ -14526,7 +14526,10 @@ * // => false */ function toPath(value) { - return isArray(value) ? arrayMap(value, baseCastKey) : stringToPath(value); + if (isArray(value)) { + return arrayMap(value, baseCastKey); + } + return isSymbol(value) ? [value] : stringToPath(value); } /** diff --git a/test/test.js b/test/test.js index 7738305f6..982f412ed 100644 --- a/test/test.js +++ b/test/test.js @@ -22111,6 +22111,21 @@ }); }); + QUnit.test('should not coerce symbols to strings', function(assert) { + assert.expect(4); + + if (Symbol) { + var object = Object(symbol); + lodashStable.each([symbol, object, [symbol], [object]], function(value) { + var actual = _.toPath(value); + assert.ok(lodashStable.isSymbol(actual[0])); + }); + } + else { + skipAssert(assert, 4); + } + }); + QUnit.test('should handle complex paths', function(assert) { assert.expect(1);