Skip to content

Commit 36ac373

Browse files
committed
Handle undefined stringify result
1 parent 1ff2133 commit 36ac373

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

javascript-stringify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
var values = array.map(function (value) {
101101
var str = stringify(value);
102102

103-
if (value === undefined) {
103+
if (str === undefined) {
104104
return String(str)
105105
}
106106

test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ describe('javascript-stringify', function () {
101101

102102
expect(stringify(obj)).to.equal("{key:'value'}");
103103
});
104+
105+
it('should omit array value', function () {
106+
var obj = [1, 2, 3];
107+
obj.push(obj);
108+
109+
expect(stringify(obj)).to.equal("[1,2,3,undefined]");
110+
});
104111
});
105112

106113
describe('custom spaces', function () {

0 commit comments

Comments
 (0)