From 66f8be523a55946a3c2f2f73e7df0b7523537fb0 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 30 May 2023 11:58:46 +0530 Subject: [PATCH] refactor: ignore invalid limit and offset Signed-off-by: Pranav C --- packages/nocodb/src/db/BaseModelSqlv2.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 21ec90095c..d1230d2b3f 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -1518,14 +1518,25 @@ class BaseModelSqlv2 { obj.shuffle = args.shuffle || args.r || ''; obj.condition = args.condition || args.c || {}; obj.conditionGraph = args.conditionGraph || {}; + + // use default value if invalid limit + // for example, if limit is not a number, it will be ignored + // if limit is less than 1, it will be ignored + const limit = +(args.limit || args.l); obj.limit = Math.max( Math.min( - args.limit || args.l || this.config.limitDefault, + limit && limit > 0 && Number.isInteger(limit) + ? limit + : this.config.limitDefault, this.config.limitMax, ), this.config.limitMin, ); - obj.offset = Math.max(+(args.offset || args.o) || 0, 0); + + // skip any invalid offset, ignore negative and non-integer values + const offset = +(args.offset || args.o) || 0; + obj.offset = Math.max(Number.isInteger(offset) ? offset : 0, 0); + obj.fields = args.fields || args.f; obj.sort = args.sort || args.s; return obj;