diff --git a/cjs/index.js b/cjs/index.js index a4833a5..c70b024 100644 --- a/cjs/index.js +++ b/cjs/index.js @@ -86,7 +86,7 @@ exports.parse = parse; */ const stringify = (value, replacer, space) => { const $ = replacer && typeof replacer === object ? - (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) : + function (k, v) { return k === '' || Array.isArray(this) || -1 < replacer.indexOf(k) ? v : void 0; } : (replacer || noop); const known = new Map; const input = []; diff --git a/esm/index.js b/esm/index.js index eb2da2d..2ea6a5f 100644 --- a/esm/index.js +++ b/esm/index.js @@ -84,7 +84,7 @@ export const parse = (text, reviver) => { */ export const stringify = (value, replacer, space) => { const $ = replacer && typeof replacer === object ? - (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) : + function (k, v) { return k === '' || Array.isArray(this) || -1 < replacer.indexOf(k) ? v : void 0; } : (replacer || noop); const known = new Map; const input = []; diff --git a/test/index.js b/test/index.js index 85c18fd..6a1a52e 100644 --- a/test/index.js +++ b/test/index.js @@ -390,6 +390,16 @@ if (typeof Symbol !== 'undefined') { ); }()); +(function () { + var a = ['a', 'b', 'c']; + var json = JSON.stringify(a, ['0']); + var restored = Flatted.parse(Flatted.stringify(a, ['0'])); + console.assert( + JSON.stringify(restored) === json, + 'whitelisted replacer does not filter Array values: '+ json + ); +}()); + (function () { var a = { b: { '': { c: { d: 1 } } } }; a._circular = a.b[''];