From 150f0ee766385ee72462af2e43414549754221c6 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Fri, 10 Mar 2023 05:36:07 -0800 Subject: [PATCH] Use replace instead of replace all so that we are compatible with v78 (#18080) * Use replace instead of replace all so that we are compatible with v78 * Add unit tests --- ui/helpers/utils/util.js | 2 +- ui/helpers/utils/util.test.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ui/helpers/utils/util.js b/ui/helpers/utils/util.js index eeef079bf..f6804c1f1 100644 --- a/ui/helpers/utils/util.js +++ b/ui/helpers/utils/util.js @@ -560,5 +560,5 @@ export const sanitizeString = (value) => { return value; } const regex = /\u202E/giu; - return value.replaceAll(regex, '\\u202E'); + return value.replace(regex, '\\u202E'); }; diff --git a/ui/helpers/utils/util.test.js b/ui/helpers/utils/util.test.js index 228d58404..e4d152658 100644 --- a/ui/helpers/utils/util.test.js +++ b/ui/helpers/utils/util.test.js @@ -565,4 +565,28 @@ describe('util', () => { expect(result.do_not_display_2).toBeUndefined(); }); }); + + describe('sanitizeString', () => { + it('should return the passed value, unchanged, if it is falsy', () => { + expect(util.sanitizeString('')).toStrictEqual(''); + }); + + it('should return the passed value, unchanged, if it is not a string', () => { + expect(util.sanitizeString(true)).toStrictEqual(true); + }); + + it('should return a truthy string that oes not match the sanitizeString regex, unchanged', () => { + expect( + util.sanitizeString('The Quick Brown Fox Jumps Over The Lazy Dog'), + ).toStrictEqual('The Quick Brown Fox Jumps Over The Lazy Dog'); + }); + + it('should return a string that matches sanitizeString regex with the matched characters replaced', () => { + expect( + util.sanitizeString( + 'The Quick Brown \u202EFox Jumps Over The Lazy Dog', + ), + ).toStrictEqual('The Quick Brown \\u202EFox Jumps Over The Lazy Dog'); + }); + }); });