fix: fix regex detection

This commit is contained in:
tdurieux
2023-02-06 13:04:35 +01:00
parent f897b5ba5b
commit d01c839616
2 changed files with 3 additions and 3 deletions

View File

@@ -1233,7 +1233,7 @@ angular
function anonymize() {
$scope.anonymize.terms.$setValidity("regex", true);
// check if string has regex characters
if ($scope.terms && $scope.terms.match(/[-[\]{}()*+?.,\\^$|#\s]/g)) {
if ($scope.terms && $scope.terms.match(/[-[\]{}()*+?.,\\^$|#]/g)) {
$scope.anonymize.terms.$setValidity("regex", false);
}
const urlRegex =

View File

@@ -141,7 +141,7 @@ export function anonymizeContent(
new RegExp(term, "gi");
} catch {
// escape regex characters
term = term.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
term = term.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
}
// remove whole url if it contains the term
content = content.replace(urlRegex, (match) => {
@@ -169,7 +169,7 @@ export function anonymizePath(path: string, terms: string[]) {
new RegExp(term, "gi");
} catch {
// escape regex characters
term = term.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
term = term.replace(/[-[\]{}()*+?.,\\^$|#]/g, "\\$&");
}
path = path.replace(
new RegExp(term, "gi"),