Pārlūkot izejas kodu

[frontend] Fix issue where the html binding returns an "undefined" string for undefined values

Johan Ahlen 5 gadi atpakaļ
vecāks
revīzija
1a1fb64166

+ 4 - 30
desktop/core/src/desktop/js/utils/hueUtils.test.js → desktop/core/src/desktop/js/utils/hueUtils.test.ts

@@ -17,36 +17,6 @@
 import hueUtils from './hueUtils';
 
 describe('hue.utils.js', () => {
-  // In polyfills.js
-  // it("should skip the milliseconds in number format if the time is more than 60 seconds", function() {
-  //   expect(Number(10000000344).toHHMMSS()).toEqual('115d, 17h, 46m, 40s');
-  // });
-
-  // In polyfills.js
-  // it("should show the milliseconds in number format if the time is less than 60 seconds", function() {
-  //   expect(Number(10123).toHHMMSS()).toEqual('10.12s');
-  // });
-
-  // In polyfills.js
-  // it("should skip the seconds if it's zero and it's specified in the function", function() {
-  //   expect(Number(60000).toHHMMSS(true)).toEqual('1m');
-  // });
-
-  // In polyfills.js
-  // it("should have the String.startsWith polyfill", function() {
-  //   expect('banana'.startsWith('ba')).toBeTruthy();
-  // });
-
-  // In polyfills.js
-  // it("should have the String.endsWith polyfill", function() {
-  //   expect('banana'.endsWith('na')).toBeTruthy();
-  // });
-
-  // In polyfills.js
-  // it("should have the String.includes polyfill", function() {
-  //   expect('banana'.includes('anan')).toBeTruthy();
-  // });
-
   it('should change completely the URL', () => {
     hueUtils.changeURL('/banana');
 
@@ -70,6 +40,10 @@ describe('hue.utils.js', () => {
     hueUtils.changeURL('/jasmine');
   });
 
+  it('should return empty string when the value is undefined', () => {
+    expect(hueUtils.deXSS(undefined)).toEqual('');
+  });
+
   it('should remove JS code from a string', () => {
     expect(hueUtils.deXSS('hello <script>alert(123)</script>world')).toEqual('hello world');
   });

+ 1 - 1
desktop/core/src/desktop/js/utils/hueUtils.ts

@@ -303,7 +303,7 @@ export const logError = (error: unknown): void => {
 export const equalIgnoreCase = (a?: string, b?: string): boolean =>
   !!a && !!b && a.toLowerCase() === b.toLowerCase();
 
-const deXSS = (str: string): string => sanitizeHtml(str);
+export const deXSS = (str?: string): string => (str && sanitizeHtml(str)) || '';
 
 export const getStyleFromCSSClass = (
   cssClass: string