Fix crash when using FullTextSearch with only asterisks in query
This commit is contained in:
		| @@ -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; | ||||
|   | ||||
| @@ -1,5 +1,5 @@ | ||||
| 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 { parseDynamicSortBy } from '../../../helpers/prisma_helpers.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 | ||||
| 		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 | ||||
| 			if (!value.count) { | ||||
| 				// get all entrys | ||||
|   | ||||
		Reference in New Issue
	
	Block a user