-
-
Notifications
You must be signed in to change notification settings - Fork 868
Closed
Labels
Description
arrayLimit before 6.14.1 applied only to queries like param[10]=value and restricted the maximum index - with the default 20 a[20]=x was accepted and a[21]=x would cause a change from array to an object.
Lines 285 to 286 in 6bdfaf5
| **qs** will also limit specifying indices in an array to a maximum index of `20`. | |
| Any array members with an index of greater than `20` will instead be converted to an object with the index as the key. |
6.14.1 enforces arrayLimit also if there is no index, but then it applies to length, therefore allowing 1 element less. For example:
const qs = require("qs");
// With N=4, the index of last element is 3 and the documentation (readme) says:
// > **qs** will also limit specifying indices in an array to a maximum index of `20`.
// > Any array members with an index of greater than `20` will instead be converted to an object with the index as the key.
// https://github.com/ljharb/qs/blob/6bdfaf5b7c33008ff603af7772844579b42f7a3f/README.md?plain=1#L285-L286
const N = 4;
const settings = {
arrayLimit: 3
};
const t1 = Array(N).fill("param[]=val").join("&");
const p1 = qs.parse(t1, settings);
console.log(p1);
// { param: { '0': 'val', '1': 'val', '2': 'val', '3': 'val' } }
const t2 = Array(N).fill().map((_, i) => `param[${i}]=val`).join("&");
const p2 = qs.parse(t2, settings);
console.log(p2);
// { param: [ 'val', 'val', 'val', 'val' ] }Reactions are currently unavailable