From 1b7a52ed5b686899df5ab2b11d482a50a1ab19a2 Mon Sep 17 00:00:00 2001 From: Alvaro Viebrantz Date: Mon, 10 Jul 2023 12:33:18 -0700 Subject: [PATCH] fix: encode values with null prototype (#1219) --- src/table.ts | 2 +- test/table.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/table.ts b/src/table.ts index f264f5e0..86c21747 100644 --- a/src/table.ts +++ b/src/table.ts @@ -570,7 +570,7 @@ class Table extends ServiceObject { 'BigQueryTimestamp', 'Geography', ]; - const constructorName = value.constructor.name; + const constructorName = value.constructor?.name; const isCustomType = customTypeConstructorNames.indexOf(constructorName) > -1; diff --git a/test/table.ts b/test/table.ts index b224bb08..3edc92e1 100644 --- a/test/table.ts +++ b/test/table.ts @@ -434,6 +434,14 @@ describe('BigQuery/Table', () => { '-99999999999999999999999999999.999999999' ); }); + + it('should return properly encode objects with null prototype', () => { + const obj = Object.create(null); + obj['name'] = 'Test'; + assert.deepStrictEqual(Table.encodeValue_(obj), { + name: 'Test', + }); + }); }); describe('formatMetadata_', () => {