Skip to content

Commit fa0d18a

Browse files
author
kauanAfonso
committed
fix: arrayLimit default configured to be 30
Signed-off-by: kauanAfonso <kauan.afonso@ibm.com>
1 parent 3daff92 commit fa0d18a

2 files changed

Lines changed: 7 additions & 16 deletions

File tree

packages/rest/src/__tests__/acceptance/request-parsing/array-limit.acceptance.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Query parameter array limit', () => {
1919
if (app) await app.stop();
2020
});
2121

22-
context('with default arrayLimit (100)', () => {
22+
context('with default arrayLimit (30)', () => {
2323
beforeEach(async () => {
2424
app = givenApplication();
2525
await app.start();
@@ -34,26 +34,17 @@ describe('Query parameter array limit', () => {
3434
expect(response.body.ids).to.eql(ids);
3535
});
3636

37-
it('parses arrays with 21 items correctly', async () => {
38-
const ids = Array.from({length: 21}, (_, i) => (i + 1).toString());
39-
const query = ids.map(id => `ids=${id}`).join('&');
40-
41-
const response = await client.get(`/test?${query}`).expect(200);
42-
expect(response.body.ids).to.eql(ids);
43-
expect(Array.isArray(response.body.ids)).to.be.true();
44-
});
45-
46-
it('parses arrays with 100 items correctly', async () => {
47-
const ids = Array.from({length: 100}, (_, i) => (i + 1).toString());
37+
it('parses arrays with 30 items correctly', async () => {
38+
const ids = Array.from({length: 30}, (_, i) => (i + 1).toString());
4839
const query = ids.map(id => `ids=${id}`).join('&');
4940

5041
const response = await client.get(`/test?${query}`).expect(200);
5142
expect(response.body.ids).to.eql(ids);
5243
expect(Array.isArray(response.body.ids)).to.be.true();
5344
});
5445

55-
it('converts arrays with 101+ items to objects (exceeds default limit)', async () => {
56-
const ids = Array.from({length: 101}, (_, i) => (i + 1).toString());
46+
it('converts arrays with 31+ items to objects (exceeds default limit)', async () => {
47+
const ids = Array.from({length: 31}, (_, i) => (i + 1).toString());
5748
const query = ids.map(id => `ids=${id}`).join('&');
5849

5950
await client.get(`/test?${query}`).expect(400);

packages/rest/src/rest.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export class RestServer
330330
}
331331

332332
// Configure query parser with custom arrayLimit if provided
333-
const arrayLimit = this.config.queryParser?.arrayLimit ?? 100;
333+
const arrayLimit = this.config.queryParser?.arrayLimit ?? 30;
334334
this._expressApp.set('query parser', (str: string) => {
335335
return qs.parse(str, {
336336
arrayLimit,
@@ -1201,7 +1201,7 @@ export interface RestServerResolvedOptions {
12011201
* The qs library defaults to 20 to prevent DoS attacks with large array indices.
12021202
* Set this to a higher value if your API needs to handle more than 20 array items.
12031203
*
1204-
* @default 100
1204+
* @default 30
12051205
* @see https://github.com/ljharb/qs#parsing-arrays
12061206
*/
12071207
arrayLimit?: number;

0 commit comments

Comments
 (0)