core: use case-sensitive query

pull/470/head
undefined 2 years ago
parent 076e2097c0
commit c5ad6599a8

@ -330,8 +330,7 @@ export class ProblemModel {
} }
static async getPrefixList(domainId: string, prefix: string) { static async getPrefixList(domainId: string, prefix: string) {
prefix = prefix.toLowerCase(); const $regex = new RegExp(`^${escapeRegExp(prefix.toLowerCase())}`, 'i');
const $regex = new RegExp(`\\A${escapeRegExp(prefix)}`, 'gmi');
const filter = { $or: [{ pid: { $regex } }, { title: { $regex } }] }; const filter = { $or: [{ pid: { $regex } }, { title: { $regex } }] };
return await document.getMulti(domainId, document.TYPE_PROBLEM, filter, ['domainId', 'docId', 'pid', 'title']) return await document.getMulti(domainId, document.TYPE_PROBLEM, filter, ['domainId', 'docId', 'pid', 'title'])
.limit(20).toArray(); .limit(20).toArray();

@ -60,7 +60,7 @@ export class StorageModel {
if (target.includes('..') || target.includes('//')) throw new Error('Invalid path'); if (target.includes('..') || target.includes('//')) throw new Error('Invalid path');
if (target.length && !target.endsWith('/')) target += '/'; if (target.length && !target.endsWith('/')) target += '/';
const results = await StorageModel.coll.find({ const results = await StorageModel.coll.find({
path: { $regex: new RegExp(`^${escapeRegExp(target)}${recursive ? '' : '[^/]+$'}`, 'i') }, path: { $regex: `^${escapeRegExp(target)}${recursive ? '' : '[^/]+$'}` },
autoDelete: null, autoDelete: null,
}).toArray(); }).toArray();
return results.map((i) => ({ return results.map((i) => ({

@ -367,8 +367,7 @@ class UserModel {
@ArgMethod @ArgMethod
static async getPrefixList(domainId: string, prefix: string, limit: number = 50) { static async getPrefixList(domainId: string, prefix: string, limit: number = 50) {
prefix = prefix.toLowerCase(); const $regex = `^${escapeRegExp(prefix.toLowerCase())}`;
const $regex = new RegExp(`\\A${escapeRegExp(prefix)}`, 'gmi');
const udocs = await coll.find({ unameLower: { $regex } }) const udocs = await coll.find({ unameLower: { $regex } })
.limit(limit).project({ _id: 1 }).toArray(); .limit(limit).project({ _id: 1 }).toArray();
const users = []; const users = [];

Loading…
Cancel
Save