diff --git a/api/migrations/config/create.ts b/api/migrations/config/create.ts index 57efe3bb..5c94004c 100644 --- a/api/migrations/config/create.ts +++ b/api/migrations/config/create.ts @@ -11,7 +11,7 @@ import fs from 'fs'; import path from 'path'; -import { escapeRegularExpression } from '@/utils/helpers/string'; +import _ from 'lodash'; // Get the argument passed (e.g., "all-users-fr") const arg: string | undefined = process.argv[2]; @@ -27,8 +27,7 @@ const templatePath: string = path.join(__dirname, '../config/template.ts'); // Check if a migration with the same name (excluding timestamp) already exists const migrationExists: boolean = fs.readdirSync(migrationsDir).some((file) => { - const escapedRegExp = escapeRegularExpression(arg); - const regex = new RegExp(`^[0-9]+-${escapedRegExp}\.ts$`); + const regex = new RegExp(`^[0-9]+-${_.escapeRegExp(arg)}\.ts$`); return regex.test(file); }); diff --git a/api/package-lock.json b/api/package-lock.json index b38dbe1c..b0358ea8 100644 --- a/api/package-lock.json +++ b/api/package-lock.json @@ -67,6 +67,7 @@ "@types/express": "^4.17.17", "@types/express-session": "^1.17.10", "@types/jest": "^29.5.2", + "@types/lodash": "^4.17.9", "@types/minio": "^7.1.1", "@types/module-alias": "^2.0.4", "@types/multer": "^1.4.11", @@ -6027,6 +6028,12 @@ "@types/node": "*" } }, + "node_modules/@types/lodash": { + "version": "4.17.9", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.9.tgz", + "integrity": "sha512-w9iWudx1XWOHW5lQRS9iKpK/XuRhnN+0T7HvdCCd802FYkT1AMTnxndJHGrNJwRoRHkslGr4S29tjm1cT7x/7w==", + "dev": true + }, "node_modules/@types/mime": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz", diff --git a/api/package.json b/api/package.json index 673b7b78..238d822e 100644 --- a/api/package.json +++ b/api/package.json @@ -91,6 +91,7 @@ "@types/express": "^4.17.17", "@types/express-session": "^1.17.10", "@types/jest": "^29.5.2", + "@types/lodash": "^4.17.9", "@types/module-alias": "^2.0.4", "@types/multer": "^1.4.11", "@types/node": "^20.3.1", diff --git a/api/src/utils/helpers/string.ts b/api/src/utils/helpers/string.ts deleted file mode 100644 index 574f7b38..00000000 --- a/api/src/utils/helpers/string.ts +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright © 2024 Hexastack. All rights reserved. - * - * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: - * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. - * 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file). - * 3. SaaS Restriction: This software, or any derivative of it, may not be used to offer a competing product or service (SaaS) without prior written consent from Hexastack. Offering the software as a service or using it in a commercial cloud environment without express permission is strictly prohibited. - */ - -const reRegExpSpecialChars = /[\\^$.*+?()[\]{}|]/g, - reHasRegularExpressionChar = RegExp(reRegExpSpecialChars.source); - -export const escapeRegularExpression = (string: string) => - string && reHasRegularExpressionChar.test(string) - ? string.replace(reRegExpSpecialChars, '\\$&') - : string; diff --git a/api/src/utils/pipes/search-filter.pipe.ts b/api/src/utils/pipes/search-filter.pipe.ts index fe62e879..6ba8c916 100644 --- a/api/src/utils/pipes/search-filter.pipe.ts +++ b/api/src/utils/pipes/search-filter.pipe.ts @@ -13,9 +13,9 @@ import { ArgumentMetadata, Logger, } from '@nestjs/common'; +import _ from 'lodash'; import { TFilterQuery, Types } from 'mongoose'; -import { escapeRegularExpression } from '../helpers/string'; import { TFilterNestedKeysOfType, TSearchFilterValue, @@ -37,7 +37,7 @@ export class SearchFilterPipe } private getRegexValue(val: string) { - const escapedRegExp = escapeRegularExpression(val); + const escapedRegExp = _.escapeRegExp(val); return new RegExp(escapedRegExp, 'i'); }