From f13af35138d6948447a097fb9e3e6356c629d6d9 Mon Sep 17 00:00:00 2001 From: Alexandre Amalric Date: Tue, 28 Nov 2023 22:31:10 +0100 Subject: [PATCH] Escape regexp to fix tests --- .../src/FormatValue/FormatValue.component.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/components/src/FormatValue/FormatValue.component.js b/packages/components/src/FormatValue/FormatValue.component.js index 98e219a3139..b620b9fd0fc 100644 --- a/packages/components/src/FormatValue/FormatValue.component.js +++ b/packages/components/src/FormatValue/FormatValue.component.js @@ -1,6 +1,7 @@ import { useTranslation } from 'react-i18next'; import classNames from 'classnames'; +import { escapeRegExp } from 'lodash'; import PropTypes from 'prop-types'; import I18N_DOMAIN_COMPONENTS from '../constants'; @@ -103,14 +104,14 @@ export function FormatValueComponent({ value, className }) { let formattedValue = value; if (typeof value === 'string') { - const regExp = new RegExp('(' + value.trim() + ')'); - const hiddenCharsRegExpMatch = value.split(regExp); + const regExp = new RegExp(`(${escapeRegExp(value.trim())})`); + const hiddenCharsRegExpSplit = value.split(regExp); if ( - hiddenCharsRegExpMatch[0] || - hiddenCharsRegExpMatch[2] || + hiddenCharsRegExpSplit[0] || + hiddenCharsRegExpSplit[2] || REG_EXP_LINE_FEEDING.test(value) ) { - formattedValue = hiddenCharsRegExpMatch + formattedValue = hiddenCharsRegExpSplit .flatMap((flatMapValue, index) => flatMapValue?.split(SPLIT_REGEX[index])) .filter(isEmptyCharacter) .map((mappedValue, index) => replaceCharacterByIcon(mappedValue, index, t));