From f5882575536624ed3a32bb6e3ff1919fa17e366d Mon Sep 17 00:00:00 2001 From: David Luecke Date: Tue, 23 Mar 2021 09:42:39 -0700 Subject: [PATCH] fix(adapter-commons): Always respect paginate.max (#2267) --- packages/adapter-commons/src/filter-query.ts | 5 +++-- packages/adapter-commons/test/filter-query.test.ts | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/adapter-commons/src/filter-query.ts b/packages/adapter-commons/src/filter-query.ts index d1db78206c..415ac54cbc 100644 --- a/packages/adapter-commons/src/filter-query.ts +++ b/packages/adapter-commons/src/filter-query.ts @@ -12,8 +12,9 @@ function parse (number: any) { // Returns the pagination limit and will take into account the // default and max pagination settings function getLimit (limit: any, paginate: any) { - if (paginate && paginate.default) { - const lower = typeof limit === 'number' && !isNaN(limit) ? limit : paginate.default; + if (paginate && (paginate.default || paginate.max)) { + const base = paginate.default || 0; + const lower = typeof limit === 'number' && !isNaN(limit) ? limit : base; const upper = typeof paginate.max === 'number' ? paginate.max : Number.MAX_VALUE; return Math.min(lower, upper); diff --git a/packages/adapter-commons/test/filter-query.test.ts b/packages/adapter-commons/test/filter-query.test.ts index 6695bcc3a0..4973ca4567 100644 --- a/packages/adapter-commons/test/filter-query.test.ts +++ b/packages/adapter-commons/test/filter-query.test.ts @@ -113,6 +113,18 @@ describe('@feathersjs/adapter-commons/filterQuery', () => { assert.strictEqual(filters.$limit, 5); }); + + it('limits to 0 when no paginate.default and not a number', () => { + const { filters } = filterQuery({ $limit: 'something' }, { paginate: { max: 10 } }); + + assert.strictEqual(filters.$limit, 0); + }); + + it('still uses paginate.max when there is no paginate.default (#2104)', () => { + const { filters } = filterQuery({ $limit: 100 }, { paginate: { max: 10 } }); + + assert.strictEqual(filters.$limit, 10); + }); }); });