From 9ff74dc069bae68c4d0ca3ccc9cae1d2f0f81588 Mon Sep 17 00:00:00 2001 From: Jesse Rolheiser Date: Wed, 5 Feb 2020 10:26:07 -0600 Subject: [PATCH] fix(pipe): handle non string input (#893) --- projects/ngx-translate/core/src/lib/translate.pipe.ts | 2 +- projects/ngx-translate/core/tests/translate.pipe.spec.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/projects/ngx-translate/core/src/lib/translate.pipe.ts b/projects/ngx-translate/core/src/lib/translate.pipe.ts index cb2ee1c4..e10ecb27 100644 --- a/projects/ngx-translate/core/src/lib/translate.pipe.ts +++ b/projects/ngx-translate/core/src/lib/translate.pipe.ts @@ -37,7 +37,7 @@ export class TranslatePipe implements PipeTransform, OnDestroy { } transform(query: string, ...args: any[]): any { - if (!query || query.length === 0) { + if (!query || !query.length) { return query; } diff --git a/projects/ngx-translate/core/tests/translate.pipe.spec.ts b/projects/ngx-translate/core/tests/translate.pipe.spec.ts index 9e4e5384..36da3118 100644 --- a/projects/ngx-translate/core/tests/translate.pipe.spec.ts +++ b/projects/ngx-translate/core/tests/translate.pipe.spec.ts @@ -161,6 +161,15 @@ describe('TranslatePipe', () => { }).toThrowError(`Wrong parameter in TranslatePipe. Expected a valid Object, received: ${param}`); }); + it("should return given falsey or non length query", () => { + translate.setTranslation('en', {"TEST": "This is a test"}); + translate.use('en'); + + expect(translatePipe.transform(null)).toBeNull(); + expect(translatePipe.transform(undefined)).toBeUndefined(); + expect(translatePipe.transform(1234 as any)).toBe(1234); + }); + describe('should update translations on lang change', () => { it('with fake loader', (done) => { translate.setTranslation('en', {"TEST": "This is a test"});