From 1953c2df793beadbd9116e521bc2f9890f01a5d6 Mon Sep 17 00:00:00 2001 From: Vildan Softic Date: Tue, 18 Feb 2020 09:39:56 +0100 Subject: [PATCH] fix(t-attribute): undefined and null bound values if the provided value is bound to a null or undefined property the resulting value for translation should be an empty string fixes issue https://github.com/aurelia/i18n/issues/313 --- package-lock.json | 58 +++++++++++++++++++++-------------- src/i18n.ts | 2 +- test/unit/t-attribute.spec.ts | 34 ++++++++++++++++++++ 3 files changed, 70 insertions(+), 24 deletions(-) diff --git a/package-lock.json b/package-lock.json index 752f2702..50c592e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "aurelia-i18n", - "version": "3.0.0-beta.5", + "version": "3.0.0-beta.7", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -304,6 +304,7 @@ "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", "integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=", "dev": true, + "optional": true, "requires": { "kind-of": "^3.0.2", "longest": "^1.0.1", @@ -2847,7 +2848,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -2868,12 +2870,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2888,17 +2892,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -3015,7 +3022,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -3027,6 +3035,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3041,6 +3050,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3048,12 +3058,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -3072,6 +3084,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -3152,7 +3165,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -3164,6 +3178,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -3249,7 +3264,8 @@ "safe-buffer": { "version": "5.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -3285,6 +3301,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -3304,6 +3321,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -3347,12 +3365,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, @@ -3360,10 +3380,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/full-icu/-/full-icu-1.2.1.tgz", "integrity": "sha512-E2s1b4GVbt8PyG+iaRN6ks8N0Oy2LOJz7SIMUwWWWx7Mr5Z08hKkfpkKQbOtOGqzkFpckDJHjjZ8qfigN2W86A==", - "dev": true, - "requires": { - "icu4c-data": "^0.63.2" - } + "dev": true }, "function-bind": { "version": "1.1.1", @@ -3865,12 +3882,6 @@ "safer-buffer": ">= 2.1.2 < 3" } }, - "icu4c-data": { - "version": "0.63.2", - "resolved": "https://registry.npmjs.org/icu4c-data/-/icu4c-data-0.63.2.tgz", - "integrity": "sha512-vT6/47CcBzDemlhRzkL7dZLoNvuUWjjiuKZHMt5T4dbkKAqLBh7ZQ33GU13ecC/aIcMlIdBOqtF4uIYTgWML4Q==", - "dev": true - }, "import-local": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/import-local/-/import-local-1.0.0.tgz", @@ -5134,7 +5145,8 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=", - "dev": true + "dev": true, + "optional": true }, "loose-envify": { "version": "1.4.0", diff --git a/src/i18n.ts b/src/i18n.ts index 0cc4c0ba..7d732950 100644 --- a/src/i18n.ts +++ b/src/i18n.ts @@ -187,7 +187,7 @@ export class I18N { public updateValue(node: Element & { au: any }, value: string, params: any) { if (value === null || value === undefined) { - return; + value = ""; } const keys = value.toString().split(";"); diff --git a/test/unit/t-attribute.spec.ts b/test/unit/t-attribute.spec.ts index 7637bb7c..afcb3ecb 100644 --- a/test/unit/t-attribute.spec.ts +++ b/test/unit/t-attribute.spec.ts @@ -26,4 +26,38 @@ describe("t-attribute", () => { component.dispose(); }); + + it("should convert bound integers to strings", async () => { + const expectedValue = ""; + const component = StageComponent + .withResources("mocks/rt-vm") + .inView(`

+ Undefined value +

+

+ Null value +

+

+ Zero value +

`) + .boundTo({ + undef: undefined, + nullul: null, + zero: 0 + }); + + bootstrapTestEnvironment(component, { + resources: { + en: { translation: { 1: expectedValue } } + } + }); + + await component.create(bootstrap); + + expect(document.getElementById("undefined")!.innerHTML).toBe(""); + expect(document.getElementById("null")!.innerHTML).toBe(""); + expect(document.getElementById("zero")!.innerHTML).toBe("0"); + + component.dispose(); + }); });