diff --git a/spec/stdlib/cson-spec.coffee b/spec/stdlib/cson-spec.coffee index bf0aaefcf..361eaf330 100644 --- a/spec/stdlib/cson-spec.coffee +++ b/spec/stdlib/cson-spec.coffee @@ -58,6 +58,10 @@ describe "CSON", -> expect(CSON.stringify(a: ['b'])).toBe "'a': [\n 'b'\n]" expect(CSON.stringify(a: ['b', 4])).toBe "'a': [\n 'b'\n 4\n]" + describe "when the array has an undefined value", -> + it "formats the undefined value as null", -> + expect(CSON.stringify(['a', undefined, 'b'])).toBe "[\n 'a'\n null\n 'b'\n]" + describe "when formatting an object", -> describe "when the object is empty", -> it "returns the empty string", -> diff --git a/src/stdlib/cson.coffee b/src/stdlib/cson.coffee index eab575a11..63158f006 100644 --- a/src/stdlib/cson.coffee +++ b/src/stdlib/cson.coffee @@ -28,7 +28,7 @@ module.exports = cson += @stringifyBoolean(value) else if _.isNumber(value) cson += @stringifyNumber(value) - else if _.isNull(value) + else if _.isNull(value) or value is undefined cson += @stringifyNull(value) else if _.isArray(value) cson += @stringifyArray(value, indentLevel + 2)