Skip to content

Commit

Permalink
fix: replaceProjectId should not fail when passed a Buffer (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkwlui committed Oct 30, 2018
1 parent 6fff182 commit b189964
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
15 changes: 15 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit b189964

Please sign in to comment.