fix replace all with special characters

This commit is contained in:
Huỳnh Đức Khoản
2024-12-20 14:33:36 +07:00
committed by mayswind
parent 263bf08f34
commit d0a5c93e49
+6 -1
View File
@@ -155,7 +155,12 @@ export function getObjectOwnFieldCount(object) {
}
export function replaceAll(value, originalValue, targetValue) {
return value.replaceAll(new RegExp(originalValue, 'g'), targetValue);
// Escape special characters in originalValue to safely use it in a regex pattern.
// This ensures that characters like . (dot), * (asterisk), +, ?, etc. are treated literally,
// rather than as special regex symbols.
const escapedOriginalValue = originalValue.replace(/([.*+?^=!:${}()|\-/\\])/g, '\\$1');
return value.replaceAll(new RegExp(escapedOriginalValue, 'g'), targetValue);
}
export function removeAll(value, originalValue) {