Skip to content

Commit

Permalink
fix: Check query for NaN (#1607)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Oct 7, 2019
1 parent 4bbc0d7 commit f1a781f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/adapter-commons/src/filter-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function parse (number: any) {
// default and max pagination settings
function getLimit (limit: any, paginate: any) {
if (paginate && paginate.default) {
const lower = typeof limit === 'number' ? limit : paginate.default;
const lower = typeof limit === 'number' && !isNaN(limit) ? limit : paginate.default;
const upper = typeof paginate.max === 'number' ? paginate.max : Number.MAX_VALUE;

return Math.min(lower, upper);
Expand Down
6 changes: 6 additions & 0 deletions packages/adapter-commons/test/filter-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ describe('@feathersjs/adapter-commons/filterQuery', () => {
assert.strictEqual(filters.$limit, 10);
assert.strictEqual(filtersNeg.$limit, 10);
});

it('limits with default pagination when not a number', () => {
const { filters } = filterQuery({ $limit: 'something' }, { paginate: { default: 5, max: 10 } });

assert.strictEqual(filters.$limit, 5);
});
});
});

Expand Down

0 comments on commit f1a781f

Please # to comment.