question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Long Arrays converted to Objects

See original GitHub issue

I’ve notice that when I add a long array to a query string the body parser converts it to an Object. For instance:

curl -L -G -d "arr[0]=1&arr[1]=2&arr[2]=3&arr[3]=4&arr[4]=5&arr[5]=6&arr[6]=7&arr[7]=8&arr[8]=9&arr[9]=10&arr[10]=11&arr[11]=12&arr[12]=13&arr[13]=14&arr[14]=15&arr[15]=16&arr[16]=17&arr[17]=18&arr[18]=19&arr[19]=20&arr[20]=21&arr[21]=22" http://localhost:8888/test

This will result in:

{arr: {
    '0': '1',
    '1': '2',
    '2': '3',
    '3': '4',
    '4': '5',
    '5': '6',
    '6': '7',
    '7': '8',
    '8': '9',
    '9': '10',
    '10': '11',
    '11': '12',
    '12': '13',
    '13': '14',
    '14': '15',
    '15': '16',
    '16': '17',
    '17': '18',
    '18': '19',
    '19': '20',
    '20': '21',
    '21': '22'
  }
}

It seems to work just fine if you keep the length of your array at 20 or bellow.

curl -L -G -d "arr[0]=1&arr[1]=2&arr[2]=3&arr[3]=4&arr[4]=5&arr[5]=6&arr[6]=7&arr[7]=8&arr[8]=9&arr[9]=10&arr[10]=11&arr[11]=12&arr[12]=13&arr[13]=14&arr[14]=15&arr[15]=16&arr[16]=17&arr[17]=18&arr[18]=19&arr[19]=20&arr[20]=21]" http://localhost:8888/test

{
	arr: [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22'] 
}

Any ideas why this is happening?

body-parser: v1.18.2 express: v4.12.0 node: v6.9.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

23reactions
jwerrecommented, Jan 12, 2018

Just in case anyone else comes across this the issue is discussed here:

https://github.com/expressjs/express/issues/3039

basically…

var qs = require('qs');
var app = require('express')();

app.set('query parser', function (str) {
  return qs.parse(str, { arrayLimit: Infinity });
});
3reactions
dougwilsoncommented, Jan 12, 2018

But I’ve seen that before, and the qs module will limit properties to 20, which is lame, though they did it for security reasons. Instead I have this module limit the number of properties to the number of body parameters, so normal behavior will get the arrays they expect up to any length while still mitigating the underlying security issue of arr[0]=foo&arr[999999999999999999]=bar allocating a large array and crashing the process 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Convert Array to Object - javascript - Stack Overflow
The Object.assign() method is used to copy the values of all enumerable own properties from one or more source objects to a target...
Read more >
Converting Object to an Array | SamanthaMing.com
We have 3 variations to convert an Object to an Array in JavaScript. ... Long long ago, in a far far galaxy, looping...
Read more >
How to convert an array into an object in javascript
To convert an array into an object we will create a function and give it 2 properties, an array and a key. const...
Read more >
Convert an Object to an Array in JavaScript
To convert an object to an array you use one of three methods: Object.keys() , Object.values() , and Object.entries() . Note that the...
Read more >
Convert an Array of Primitives to an Array of Objects | Baeldung
First, let's convert from a primitive array to an object array: int[] input = new int[] { 0, 1, 2, 3, 4 };...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found