From f96b79ca696d1b80285e5fc7352b2a49b2317142 Mon Sep 17 00:00:00 2001 From: Jonathan Lui Date: Wed, 14 Nov 2018 15:05:39 -0800 Subject: [PATCH] fix: do not replace projectId on stream objects --- src/index.ts | 4 +++- test/index.ts | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 0a36e32..fc5dbb6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ +import {Stream} from 'stream'; + /** * Copyright 2014 Google Inc. All Rights Reserved. * @@ -30,7 +32,7 @@ export function replaceProjectIdToken(value: any, projectId: string): any { } if (value !== null && typeof value === 'object' && - !(value instanceof Buffer) && + !(value instanceof Buffer) && !(value instanceof Stream) && typeof value.hasOwnProperty === 'function') { for (const opt in value) { if (value.hasOwnProperty(opt)) { diff --git a/test/index.ts b/test/index.ts index 914cb62..1af80e5 100644 --- a/test/index.ts +++ b/test/index.ts @@ -15,6 +15,7 @@ */ import * as assert from 'assert'; +import * as stream from 'stream'; import {replaceProjectIdToken} from '../src'; describe('projectId placeholder', () => { @@ -110,4 +111,13 @@ describe('projectId placeholder', () => { }, replaced); }); + + it('should not inject projectId into stream', () => { + // tslint:disable-next-line: no-any + const transform = new stream.Transform() as any; + transform.prop = 'A {{projectId}} Z'; + + const replaced = replaceProjectIdToken(transform, PROJECT_ID); + assert.deepEqual(transform.prop, replaced.prop); + }); });