From 84feaf369d65710dd7b2a7e1e49998674c4b4b5f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 4 Feb 2013 08:52:07 -0800 Subject: [PATCH] Format undefined array values as null --- spec/stdlib/cson-spec.coffee | 4 ++++ src/stdlib/cson.coffee | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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)