fix: escape regular expressions

This commit is contained in:
yassinedorbozgithub
2024-09-24 05:21:00 +01:00
parent 37f20f7d79
commit fcfc68187b
3 changed files with 23 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ import {
} from '@nestjs/common';
import { TFilterQuery, Types } from 'mongoose';
import { escapeRegularExpression } from '../helpers/string';
import {
TFilterNestedKeysOfType,
TSearchFilterValue,
@@ -36,9 +37,8 @@ export class SearchFilterPipe<T>
}
private getRegexValue(val: string) {
const quote = (str: string) =>
str.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1');
return new RegExp(quote(val), 'i');
const escapedRegExp = escapeRegularExpression(val);
return new RegExp(escapedRegExp, 'i');
}
private isAllowedField(field: string) {