Fix crash when using FullTextSearch with only asterisks in query

This commit is contained in:
Leon Meier 2025-02-02 19:47:32 +01:00
parent fa26595797
commit 7674653eec
2 changed files with 17 additions and 1 deletions

View File

@ -37,4 +37,16 @@ export function handlePrismaError(errorObj: any, res: Response, source: string)
} }
} }
/**
* Checks if the given query only contains stars
*
* @export
* @param {string} fts_query FullTextSearch query
* @returns {boolean} Does the query only contains *?
*/
export function FTS_starChecker(fts_query: string) {
return(new RegExp("^[*]+$").test(fts_query));
}
export default prisma; export default prisma;

View File

@ -1,5 +1,5 @@
import { Request, Response } from 'express'; import { Request, Response } from 'express';
import db, { handlePrismaError } from '../../../handlers/db.js'; // Database import db, { handlePrismaError, FTS_starChecker } from '../../../handlers/db.js'; // Database
import log from '../../../handlers/log.js'; import log from '../../../handlers/log.js';
import { parseDynamicSortBy } from '../../../helpers/prisma_helpers.js'; import { parseDynamicSortBy } from '../../../helpers/prisma_helpers.js';
import { schema_get, schema_post, schema_patch, schema_del } from './alertContacts_schema.js'; import { schema_get, schema_post, schema_patch, schema_del } from './alertContacts_schema.js';
@ -15,6 +15,10 @@ async function get(req: Request, res: Response) {
// Query with FullTextSearch // Query with FullTextSearch
if (value.search !== undefined || value.id !== undefined) { if (value.search !== undefined || value.id !== undefined) {
if (value.search !== undefined && FTS_starChecker(value.search)) {
res.status(400).json({ status: 'ERROR', errorcode: 'VALIDATION_ERROR', message: 'Search query cannot contain only asterisk/s (*)' });
return;
}
// with FullTextSearch // with FullTextSearch
if (!value.count) { if (!value.count) {
// get all entrys // get all entrys