Skip to content

Commit ccb2a04

Browse files
committed
bugfix(#1303): use hasOwn function on Object + test coverage
1 parent c364902 commit ccb2a04

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

packages/serialize/src/index.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ 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-
if (!Object.prototype.hasOwnProperty.call(data, k) || ignore) {
32-
continue;
33-
}
31+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
32+
if (!Object.hasOwn(data, k) || ignore) {
33+
continue;
34+
}
3435

3536
if (!first) {
3637
s += ',';

packages/serialize/test/test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ 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+
80+
t.expect(result).toStrictEqual('{"someKey":"value"}');
81+
});
82+
7483
test.it('removes the first colon from strings not prefixed by base64', t => {
7584
const json = JSON.stringify({
7685
simple: ':hello',

0 commit comments

Comments
 (0)