Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get request with one-item array param, will send the value inside instead the the array #521

Closed
choyzer opened this issue Jan 22, 2023 · 1 comment
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@choyzer
Copy link

choyzer commented Jan 22, 2023

Environment details

  • OS: macOS
  • Node.js version: v18.12.1
  • npm version: 8.19.2
  • gaxios version: 5.0.2

Steps to reproduce

Send a simple GET request with an one-item-array as part of the params using gaxios
http://localhost/someEndpoint?account_ids[]=Y&shopId=X

The server is getting the request (someEndpoint), will get account_ids=Y, instead of account_ids =[Y]
The req.query.account_ids will be equal Y instead [Y]

This is happening only on arrays with one item, in multiple items are working fine

In axios it's working fine.

@choyzer choyzer added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jan 22, 2023
@sofisl
Copy link
Contributor

sofisl commented May 23, 2023

Hi @choyzer, thanks for submitting this. For our use case, I think this is working as intended. We use the paramsSerializer method from the Node core library, which parses arrays in this way:

querystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' });
// Returns 'foo=bar&baz=qux&baz=quux&corge='

So it actually always returns single elements without an array. Testing this locally, this request:

   const res = await request({
      url,
      params: {querystring: ['a', 'b']},
    });

returns:

https://example.com/?querystring=a&querystring=b

and

   const res = await request({
      url,
      params: {querystring: ['a', 'b']},
    });

returns

https://example.com/?querystring=a

For some more insight, in our cases, an array is a repeated field so when query string is encoded, it's literally repeated. If you really wanted to include the brackets, you could JSON.stringify the parameter and pass it as a string.

Hope this helps, feel free to reopen if you feel this still isn't resolved!

@sofisl sofisl closed this as completed May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

2 participants