From 765e26c6ced156373d504797eea7941197f530e3 Mon Sep 17 00:00:00 2001 From: Jitendra Gundaniya <38945204+jitu5@users.noreply.github.com> Date: Wed, 23 Aug 2023 13:12:19 +0100 Subject: [PATCH] Fix to search for a ' Signed-off-by: Vladimir --- RELEASE.md | 8 +++++++ src/components/node-list/node-list-row.js | 10 ++------- src/utils/index.js | 27 +++++++++++++++++++++++ src/utils/utils.test.js | 20 ++++++++++++++++- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index 658b9bea0d..1990e9f633 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -6,6 +6,14 @@ Please follow the established format: - Include the ID number for the related PR (or PRs) in parentheses --> +# Release 6.4.1 + +## Major features and improvements + +## Bug fixes and other changes + +- Fix to search for a '': '<lambda>', - '': '<partial>', -}; - /** * Returns `true` if there are no props changes, therefore the last render can be reused. * Performance: Checks only the minimal set of props known to change after first render. @@ -134,7 +128,7 @@ const NodeListRow = memo( } )} dangerouslySetInnerHTML={{ - __html: replaceMatches(label, replaceTagsWithEntities), + __html: replaceAngleBracketMatches(label), }} /> diff --git a/src/utils/index.js b/src/utils/index.js index 069e235169..554ea199e7 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -78,6 +78,33 @@ export const replaceMatches = (str, toReplace) => { } }; +/** + * Replace any parts of a string that match the '<' & '>' except '' & '' + * @param {String} str The string to check + * @returns {String} The string with or without replaced values + */ +export const replaceAngleBracketMatches = (str) => { + if (str?.length > 0) { + // Handling string like '' or '' in 3 steps + // 1. replacing all '' & '' with unique '@$1$@' & '@$2$@' respectively + // 2. replacing all '<' & '>' with '<' & '>' respectively + // 3. replacing back all '@$1$@' & '@$2$@' with & respectively + const strWithoutBTag = str + .replaceAll('', '@$1$@') + .replaceAll('', '@$2$@'); + const replacedWithAngleBracket = strWithoutBTag + .replaceAll('<', '<') + .replaceAll('>', '>'); + const result = replacedWithAngleBracket + .replaceAll('@$1$@', '') + .replaceAll('@$2$@', ''); + + return result; + } else { + return str; + } +}; + /** * Removes any parts of a string that match the regular expression * @param {String} str The string to check diff --git a/src/utils/utils.test.js b/src/utils/utils.test.js index 42b43fecc6..9f6c565a0c 100644 --- a/src/utils/utils.test.js +++ b/src/utils/utils.test.js @@ -1,4 +1,10 @@ -import { arrayToObject, getUrl, unique, replaceMatches } from './index'; +import { + arrayToObject, + getUrl, + unique, + replaceMatches, + replaceAngleBracketMatches, +} from './index'; describe('utils', () => { describe('arrayToObject', () => { @@ -59,4 +65,16 @@ describe('utils', () => { ); }); }); + + describe('replaceAngleBracketMatches', () => { + it('replaces angle bracket matched characters from a string', () => { + expect(replaceAngleBracketMatches('bda>')).toEqual( + '<lambda>' + ); + expect(replaceAngleBracketMatches('')).toEqual( + '<lambda>' + ); + expect(replaceAngleBracketMatches('')).toEqual('<lambda>'); + }); + }); });