Skip to content

Conversation

Jayesh-11
Copy link

@Jayesh-11 Jayesh-11 commented Sep 27, 2025

Fixes : #529

Currently when using parse with arrayLimit throwOnLimitExceeded: true allowSparse: true
the parser does not throw error even when above options meet the condition for throwing error,
instead it silently converts the value to object

added fix throw error early based on the index of the array if it exceeds the array limit, when allowSparse is set to true
since in that case only it would actually exceed array length

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. This is needed to handle cases when someone sent, for example, a[999999999] and it will take significant time to iterate over this huge array.

// parse.js

    } else if (
                !isNaN(index)
                && root !== decodedRoot
                && String(index) === decodedRoot
                && index >= 0
                && (options.parseArrays && index <= options.arrayLimit)   --> this is the part that fails i.e false
    ) {

consider following example

const a = parse("a[99]", {
  ignoreQueryPrefix: true,
  arrayLimit: 10,
  parameterLimit: 10,
  depth: 10,
  strictDepth: true,
  throwOnLimitExceeded: true,
  allowSparse: true,
});
RESULT : { a: { '99': '' } } // which seems incorrect even though we allow sprase here and should be throwing error instead



const a = parse("a[0]=1&a[1]=2&a[2]=3&a[10]=4", {
  ignoreQueryPrefix: true,
  arrayLimit: 6,
  parameterLimit: 10,
  depth: 10,
  strictDepth: true,
  throwOnLimitExceeded: true,
  allowSparse: true,
});
RESULT : { a: { '0': '1', '1': '2', '2': '3', '10': '4' } } // which seems incorrect even though we allow sprase here and should be throwing error instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

arrayLimit does not throw error when throwOnLimitExceeded flag is true
1 participant