diff --git a/lodash.js b/lodash.js index da840d9ed..00dc0a240 100644 --- a/lodash.js +++ b/lodash.js @@ -10351,7 +10351,10 @@ if (typeof value == 'string') { return value; } - var result = value == null ? '' : (value + ''); + if (value == null) { + return ''; + } + var result = isSymbol(value) ? symbolToString.call(value) : (value + ''); return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; } diff --git a/test/test.js b/test/test.js index e45bda636..0661b57a2 100644 --- a/test/test.js +++ b/test/test.js @@ -61,7 +61,7 @@ Set = root.Set, slice = arrayProto.slice, Symbol = root.Symbol, - symbol = Symbol ? Symbol() : undefined, + symbol = Symbol ? Symbol('a') : undefined, Uint8Array = root.Uint8Array, WeakMap = root.WeakMap; @@ -20610,6 +20610,21 @@ assert.deepEqual(actual, expected); }); + QUnit.test('should not error on symbols', function(assert) { + assert.expect(1); + + if (Symbol) { + try { + assert.strictEqual(_.toString(symbol), 'Symbol(a)'); + } catch (e) { + assert.ok(false, e.message); + } + } + else { + skipTest(assert); + } + }); + QUnit.test('should return the `toString` result of the wrapped value', function(assert) { assert.expect(1);