Skip to content

Commit

Permalink
Escape regexp to fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Amalric committed Nov 28, 2023
1 parent a34b7ca commit f13af35
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions packages/components/src/FormatValue/FormatValue.component.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit f13af35

Please sign in to comment.