Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/makeSecureDeepProxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,15 @@ describe('makeSecureDeepProxy', () => {
proxy.a[1].b;
}, /Property b is not defined in the config/);
});

it('allows JSON.stringify on secure config', () => {
const config = {
a: 1,
nested: { b: 'text' },
};

const proxy = makeSecureDeepProxy(config);

assert.equal(JSON.stringify(proxy), '{"a":1,"nested":{"b":"text"}}');
});
});
6 changes: 4 additions & 2 deletions src/makeSecureDeepProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ function makeSecureProxy<T extends DefaultConfig>(targetObject: T): T {
// Handle Symbol and Array properties
if (
typeof prop === 'symbol' ||
// Don't throw error when using array methods
(Array.isArray(target) && Number.isNaN(Number(prop)))
/** Don't throw error when using array methods */
(Array.isArray(target) && Number.isNaN(Number(prop))) ||
/** Allow stringifying proxied config (because JSON.stringify calls this method) */
prop === 'toJSON'
) {
return Reflect.get(target, prop);
}
Expand Down