Skip to content

Commit 1b7a52e

Browse files
authored
fix: encode values with null prototype (#1219)
1 parent 7f41334 commit 1b7a52e

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/table.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ class Table extends ServiceObject {
570570
'BigQueryTimestamp',
571571
'Geography',
572572
];
573-
const constructorName = value.constructor.name;
573+
const constructorName = value.constructor?.name;
574574
const isCustomType =
575575
customTypeConstructorNames.indexOf(constructorName) > -1;
576576

test/table.ts

+8
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,14 @@ describe('BigQuery/Table', () => {
434434
'-99999999999999999999999999999.999999999'
435435
);
436436
});
437+
438+
it('should return properly encode objects with null prototype', () => {
439+
const obj = Object.create(null);
440+
obj['name'] = 'Test';
441+
assert.deepStrictEqual(Table.encodeValue_(obj), {
442+
name: 'Test',
443+
});
444+
});
437445
});
438446

439447
describe('formatMetadata_', () => {

0 commit comments

Comments
 (0)