From afccedbac6f724c547d8c6df52464eeb3c716cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Le=20Ninivin?= Date: Wed, 18 Jan 2017 10:28:35 +0000 Subject: [PATCH] jio.util.stringify: Add support for undefined values `jIO.util.stringify` was raising if the value of an object was undefined, this changes fix it and provides the same behaviour as the standard `JSON.stringify` /reviewed-on https://lab.nexedi.com/nexedi/jio/merge_requests/41 --- src/jio.js | 3 +++ test/jio/util.js | 1 + 2 files changed, 4 insertions(+) diff --git a/src/jio.js b/src/jio.js index 2e07d37..9a5b054 100644 --- a/src/jio.js +++ b/src/jio.js @@ -124,6 +124,9 @@ i, value, result_list; + if (obj === undefined) { + return undefined; + } if (obj.constructor === Object) { key_list = Object.keys(obj).sort(); result_list = []; diff --git a/test/jio/util.js b/test/jio/util.js index 910dc96..b5d554f 100644 --- a/test/jio/util.js +++ b/test/jio/util.js @@ -20,6 +20,7 @@ '"2006-01-02T15:04:05.000Z"'); equal(str({ x: 5, y: 6, z: 7 }), '{"x":5,"y":6,"z":7}'); equal(str({ z: 7, y: 6, x: 5 }), '{"x":5,"y":6,"z":7}'); + equal(str({ z: "", y: undefined, x: 5 }), '{"x":5,"z":""}'); equal(str(Object.create(null, { x: { value: 'x', enumerable: false }, y: { value: 'y', enumerable: true } })), '{"y":"y"}'); -- 2.25.1