fix: logs page crash when special chars present in the value of query (#4408)

This commit is contained in:
Vikrant Gupta 2024-01-22 19:06:33 +05:30 committed by GitHub
parent d563778479
commit 79e6699b37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -122,8 +122,17 @@ export function replaceStringWithMaxLength(
if (lastSearchValue === '') {
return `${mainString}${replacementString},`;
}
/**
* We need to escape the special characters in the lastSearchValue else the
* new RegExp fails with error range out of order in char class
*/
const escapedLastSearchValue = lastSearchValue.replace(
/[-/\\^$*+?.()|[\]{}]/g,
'\\$&',
);
const updatedString = mainString.replace(
new RegExp(`${lastSearchValue}(?=[^${lastSearchValue}]*$)`),
new RegExp(`${escapedLastSearchValue}(?=[^${escapedLastSearchValue}]*$)`),
replacementString,
);
return `${updatedString},`;