From b1899641bd126536ec1f86fa8b829955ae33f8c8 Mon Sep 17 00:00:00 2001 From: Jonathan Lui Date: Tue, 30 Oct 2018 02:05:22 -0700 Subject: [PATCH] fix: replaceProjectId should not fail when passed a Buffer (#43) --- src/index.ts | 1 + test/index.ts | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/index.ts b/src/index.ts index 4ba22bc..0a36e32 100644 --- a/src/index.ts +++ b/src/index.ts @@ -30,6 +30,7 @@ export function replaceProjectIdToken(value: any, projectId: string): any { } if (value !== null && typeof value === 'object' && + !(value instanceof Buffer) && typeof value.hasOwnProperty === 'function') { for (const opt in value) { if (value.hasOwnProperty(opt)) { diff --git a/test/index.ts b/test/index.ts index 9668874..914cb62 100644 --- a/test/index.ts +++ b/test/index.ts @@ -95,4 +95,19 @@ describe('projectId placeholder', () => { }); }, /Sorry, we cannot connect/); }); + + it('should return object containing a buffer as-is', () => { + const bufferContainingObject = { + prop1: 'A {{projectId}} Z', + buf: Buffer.from('test'), + }; + + const replaced = replaceProjectIdToken(bufferContainingObject, PROJECT_ID); + assert.deepStrictEqual( + { + prop1: `A ${PROJECT_ID} Z`, + buf: Buffer.from('test'), + }, + replaced); + }); });