From 01b10d0d3b5c69aa3fde5608437dd420bdb45f4b Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 19 Jul 2024 14:32:14 +0100 Subject: [PATCH] fix drive search query `.andWhere` does not add parentheses, so that `or` changed the whole meaning of the query --- packages/backend/src/server/api/endpoints/drive/files.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/endpoints/drive/files.ts b/packages/backend/src/server/api/endpoints/drive/files.ts index 6d87d5ddf7..d615036ce8 100644 --- a/packages/backend/src/server/api/endpoints/drive/files.ts +++ b/packages/backend/src/server/api/endpoints/drive/files.ts @@ -10,6 +10,7 @@ import { QueryService } from '@/core/QueryService.js'; import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js'; import { DI } from '@/di-symbols.js'; import { sqlLikeEscape } from '@/misc/sql-like-escape.js'; +import { Brackets } from 'typeorm'; export const meta = { tags: ['drive'], @@ -63,7 +64,12 @@ export default class extends Endpoint { // eslint- } if (ps.searchQuery.length > 0) { - query.andWhere('file.name ILIKE :searchQuery OR file.comment ILIKE :searchQuery', { searchQuery: `%${sqlLikeEscape(ps.searchQuery)}%` }); + const args = { searchQuery: `%${sqlLikeEscape(ps.searchQuery)}%` }; + query.andWhere(new Brackets((qb) => { + qb + .where('file.name ILIKE :searchQuery', args) + .orWhere('file.comment ILIKE :searchQuery', args); + })); } if (ps.type) {