ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.58k stars 1.33k forks source link

fix: serialize 'application/x-www-form-urlencoded' with array indices in browser #1589

Closed dsanders11 closed 4 years ago

dsanders11 commented 4 years ago

This is a quick and dirty PR more for discussion than immediate merging.

Currently the behavior for serializing application/x-www-form-urlencoded payloads seems to differ between Node and the browser, with Node using indices for array values and the browser not. This PR tries to make the behavior consistent, with the assumption that the behavior in Node is the intended behavior.

So, open question on which environment has the intended behavior currently. I see that in Node indices are turned off for serializing the query string, but not for the payload body when it's application/x-www-form-urlencoded.

niftylettuce commented 4 years ago

I'm wondering if using a package like https://www.npmjs.com/package/qs would be best, as to ensure consistency regardless of Node/Browser changes, e.g. qs.stringify({ a: ['b', 'c', 'd'] }, { indices: true });

dsanders11 commented 4 years ago

@niftylettuce, that package is already used in the Node code, isn't it? I wasn't sure if it plays nice in the browser environment. If so, that seems like a simpler way to go as it would reduce some code and keep them consistent, as you said.

niftylettuce commented 4 years ago

Yeah qs works fine in browsers, superagent is actually built to make dist builds for browsers already so should be fine to use it for both. Would love a PR! Would be super super helpful, I'm so stressed for time

dsanders11 commented 4 years ago

@niftylettuce, made PR #1591, which just uses qs and should be quick and easy. Thanks for the feedback.

niftylettuce commented 4 years ago

v6.1.0 has been released to npm, thank you @dsanders11

https://github.com/visionmedia/superagent/releases/tag/v6.1.0