Format undefined array values as null

This commit is contained in:
Kevin Sawicki 2013-02-04 08:52:07 -08:00
parent f65e83fe2a
commit 84feaf369d
2 changed files with 5 additions and 1 deletions

View File

@ -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", ->

View File

@ -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)