From 41c10a0b950d95a710620be75629a3be01b982b3 Mon Sep 17 00:00:00 2001 From: Jitendra Gundaniya Date: Mon, 21 Aug 2023 13:32:15 +0100 Subject: [PATCH 1/3] Fix to search for a ' +# 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: replaceMatches(label), }} /> diff --git a/src/utils/index.js b/src/utils/index.js index 069e235169..20be09c69b 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -61,18 +61,27 @@ export const changed = (props, objectA, objectB) => { }; /** - * Replace any parts of a string that match the keys in the toReplace object + * Replace any parts of a string that match the '<' & '>' except '' & '' * @param {String} str The string to check - * @param {Object} toReplace The object of strings to replace and their replacements * @returns {String} The string with or without replaced values */ -export const replaceMatches = (str, toReplace) => { +export const replaceMatches = (str) => { if (str?.length > 0) { - const regex = new RegExp(Object.keys(toReplace).join('|'), 'gi'); + // 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 stgWithoutBTag = str + .replaceAll('', '@$1$@') + .replaceAll('', '@$2$@'); + const replacedWithAngleBracket = stgWithoutBTag + .replaceAll('<', '<') + .replaceAll('>', '>'); + const result = replacedWithAngleBracket + .replaceAll('@$1$@', '') + .replaceAll('@$2$@', ''); - return str.replace(regex, (matched) => { - return toReplace[matched]; - }); + return result; } else { return str; } diff --git a/src/utils/utils.test.js b/src/utils/utils.test.js index 42b43fecc6..5559d29904 100644 --- a/src/utils/utils.test.js +++ b/src/utils/utils.test.js @@ -48,15 +48,14 @@ describe('utils', () => { }); describe('replaceMatches', () => { - const entitiesToReplace = { - '<': '<', - '>': '>', - }; - it('replaces matched characters from a string', () => { - expect(replaceMatches('<lambda>', entitiesToReplace)).toEqual( - '' + expect(replaceMatches('bda>')).toEqual( + '<lambda>' + ); + expect(replaceMatches('')).toEqual( + '<lambda>' ); + expect(replaceMatches('')).toEqual('<lambda>'); }); }); }); From f1cbe64f3ebbf9c6e5b664918140d9167d28ad85 Mon Sep 17 00:00:00 2001 From: Jitendra Gundaniya Date: Mon, 21 Aug 2023 14:33:29 +0100 Subject: [PATCH 2/3] Fix for failed test cases --- src/components/node-list/node-list-row.js | 4 ++-- src/utils/index.js | 20 ++++++++++++++++- src/utils/utils.test.js | 27 +++++++++++++++++++---- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/components/node-list/node-list-row.js b/src/components/node-list/node-list-row.js index 9964ba6aa7..00d6a1fdbb 100644 --- a/src/components/node-list/node-list-row.js +++ b/src/components/node-list/node-list-row.js @@ -1,7 +1,7 @@ import React, { memo } from 'react'; import { connect } from 'react-redux'; import classnames from 'classnames'; -import { changed, replaceMatches } from '../../utils'; +import { changed, replaceAngleBracketMatches } from '../../utils'; import NodeIcon from '../icons/node-icon'; import VisibleIcon from '../icons/visible'; import InvisibleIcon from '../icons/invisible'; @@ -128,7 +128,7 @@ const NodeListRow = memo( } )} dangerouslySetInnerHTML={{ - __html: replaceMatches(label), + __html: replaceAngleBracketMatches(label), }} /> diff --git a/src/utils/index.js b/src/utils/index.js index 20be09c69b..a87f178fbc 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -60,12 +60,30 @@ export const changed = (props, objectA, objectB) => { ); }; +/** + * Replace any parts of a string that match the keys in the toReplace object + * @param {String} str The string to check + * @param {Object} toReplace The object of strings to replace and their replacements + * @returns {String} The string with or without replaced values + */ +export const replaceMatches = (str, toReplace) => { + if (str?.length > 0) { + const regex = new RegExp(Object.keys(toReplace).join('|'), 'gi'); + + return str.replace(regex, (matched) => { + return toReplace[matched]; + }); + } else { + return str; + } +}; + /** * 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 replaceMatches = (str) => { +export const replaceAngleBracketMatches = (str) => { if (str?.length > 0) { // Handling string like '' or '' in 3 steps // 1. replacing all '' & '' with unique '@$1$@' & '@$2$@' respectively diff --git a/src/utils/utils.test.js b/src/utils/utils.test.js index 5559d29904..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', () => { @@ -48,14 +54,27 @@ describe('utils', () => { }); describe('replaceMatches', () => { + const entitiesToReplace = { + '<': '<', + '>': '>', + }; + it('replaces matched characters from a string', () => { - expect(replaceMatches('bda>')).toEqual( + expect(replaceMatches('<lambda>', entitiesToReplace)).toEqual( + '' + ); + }); + }); + + describe('replaceAngleBracketMatches', () => { + it('replaces angle bracket matched characters from a string', () => { + expect(replaceAngleBracketMatches('bda>')).toEqual( '<lambda>' ); - expect(replaceMatches('')).toEqual( + expect(replaceAngleBracketMatches('')).toEqual( '<lambda>' ); - expect(replaceMatches('')).toEqual('<lambda>'); + expect(replaceAngleBracketMatches('')).toEqual('<lambda>'); }); }); }); From d03465274ed7ca2c97b5025e0b2bc7dbfde9464a Mon Sep 17 00:00:00 2001 From: Jitendra Gundaniya Date: Tue, 22 Aug 2023 12:34:20 +0100 Subject: [PATCH 3/3] Variable name updated --- src/utils/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/index.js b/src/utils/index.js index a87f178fbc..554ea199e7 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -89,10 +89,10 @@ export const replaceAngleBracketMatches = (str) => { // 1. replacing all '' & '' with unique '@$1$@' & '@$2$@' respectively // 2. replacing all '<' & '>' with '<' & '>' respectively // 3. replacing back all '@$1$@' & '@$2$@' with & respectively - const stgWithoutBTag = str + const strWithoutBTag = str .replaceAll('', '@$1$@') .replaceAll('', '@$2$@'); - const replacedWithAngleBracket = stgWithoutBTag + const replacedWithAngleBracket = strWithoutBTag .replaceAll('<', '<') .replaceAll('>', '>'); const result = replacedWithAngleBracket