Skip to content

Commit

Permalink
handle Symbol values in util.stringify()
Browse files Browse the repository at this point in the history
fix #2089
  • Loading branch information
ryym committed Feb 6, 2016
1 parent 2a85944 commit 872684f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ function jsonStringify(object, spaces, depth) {
break;
case 'boolean':
case 'regexp':
case 'symbol':
case 'number':
val = val === 0 && (1 / val) === -Infinity // `-0`
? '-0'
Expand Down Expand Up @@ -597,6 +598,7 @@ exports.canonicalize = function(value, stack) {
case 'number':
case 'regexp':
case 'boolean':
case 'symbol':
canonicalizedObj = value;
break;
default:
Expand Down
9 changes: 9 additions & 0 deletions test/acceptance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ describe('lib/utils', function () {

stringify(a).should.equal('{\n "foo": 1\n}');
});

// In old version node.js, Symbol is not available by default.
if (typeof global.Symbol === 'function') {
it('should handle Symbol', function () {
var symbol = Symbol('value');
stringify(symbol).should.equal('Symbol(value)');
stringify({symbol: symbol}).should.equal('{\n "symbol": Symbol(value)\n}')
});
}
});

describe('type', function () {
Expand Down

0 comments on commit 872684f

Please sign in to comment.