Skip to content

Commit b0b572a

Browse files
Bugfix: use Object.prototype for correct usage of hasOwnProperty (#1304)
* fix(#1303): use Object.prototype for correct usage of hasOwnProperty * bugfix(#1303): use hasOwn function on Object + test coverage --------- Co-authored-by: Jared Wray <me@jaredwray.com>
1 parent 86482b0 commit b0b572a

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/serialize/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export const defaultSerialize = (data: any): string => {
2828
// eslint-disable-next-line guard-for-in
2929
for (const k in data) {
3030
const ignore = typeof data[k] === 'function' || (!array && data[k] === undefined);
31-
// eslint-disable-next-line no-prototype-builtins
32-
if (!data.hasOwnProperty(k) || ignore) {
31+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
32+
if (!Object.hasOwn(data, k) || ignore) {
3333
continue;
3434
}
3535

packages/serialize/test/test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ test.it('defaultSerialize detects base64 on string', t => {
7171
t.expect(result.encoded.toString()).toBe('hello world');
7272
});
7373

74+
test.it('defaultSerialize accepts objects created with null', t => {
75+
const json = Object.create(null);
76+
json.someKey = 'value';
77+
78+
const result = defaultSerialize<{someKey: string}>(json);
79+
t.expect(result).toStrictEqual('{"someKey":"value"}');
80+
});
81+
7482
test.it('removes the first colon from strings not prefixed by base64', t => {
7583
const json = JSON.stringify({
7684
simple: ':hello',

0 commit comments

Comments
 (0)