mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: escape domainPrefixSearch regex
This commit is contained in:
1 file changed
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
import { Dictionary } from 'lodash';
|
import { Dictionary, escapeRegExp } from 'lodash';
|
||||||
import { LRUCache } from 'lru-cache';
|
import { LRUCache } from 'lru-cache';
|
||||||
import { Filter } from 'mongodb';
|
import { Filter } from 'mongodb';
|
||||||
import { DomainDoc } from '../interface';
|
import { DomainDoc } from '../interface';
|
||||||
@@ -268,7 +268,7 @@ class DomainModel {
|
|||||||
|
|
||||||
@ArgMethod
|
@ArgMethod
|
||||||
static async getPrefixSearch(prefix: string, limit: number = 50) {
|
static async getPrefixSearch(prefix: string, limit: number = 50) {
|
||||||
const $regex = new RegExp(prefix, 'mi');
|
const $regex = new RegExp(escapeRegExp(prefix), 'mi');
|
||||||
const ddocs = await coll.find({
|
const ddocs = await coll.find({
|
||||||
$or: [{ _id: { $regex } }, { name: { $regex } }],
|
$or: [{ _id: { $regex } }, { name: { $regex } }],
|
||||||
}).limit(limit).toArray();
|
}).limit(limit).toArray();
|
||||||
|
|||||||
Reference in new issue
Block a user