mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 18:17:48 +00:00
Ensure _.toString does not throw on symbols.
This commit is contained in:
@@ -10351,7 +10351,10 @@
|
|||||||
if (typeof value == 'string') {
|
if (typeof value == 'string') {
|
||||||
return value;
|
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;
|
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
17
test/test.js
17
test/test.js
@@ -61,7 +61,7 @@
|
|||||||
Set = root.Set,
|
Set = root.Set,
|
||||||
slice = arrayProto.slice,
|
slice = arrayProto.slice,
|
||||||
Symbol = root.Symbol,
|
Symbol = root.Symbol,
|
||||||
symbol = Symbol ? Symbol() : undefined,
|
symbol = Symbol ? Symbol('a') : undefined,
|
||||||
Uint8Array = root.Uint8Array,
|
Uint8Array = root.Uint8Array,
|
||||||
WeakMap = root.WeakMap;
|
WeakMap = root.WeakMap;
|
||||||
|
|
||||||
@@ -20610,6 +20610,21 @@
|
|||||||
assert.deepEqual(actual, expected);
|
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) {
|
QUnit.test('should return the `toString` result of the wrapped value', function(assert) {
|
||||||
assert.expect(1);
|
assert.expect(1);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user