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

Bug with url.format and object contain array #65

Closed
binggo8322 opened this issue Aug 11, 2023 · 3 comments
Closed

Bug with url.format and object contain array #65

binggo8322 opened this issue Aug 11, 2023 · 3 comments

Comments

@binggo8322
Copy link

Hello,

In the new version 0.11.1, the lib qs replace querystring, but it is not the same.

localVarUrlObj = {message:['value1','value2']}

0.11.0
url.format(localVarUrlObj) => message=value1&message=value2
0.11.1
url.format(localVarUrlObj) => message%5B0%5D=value1&message%5B1%5D=value2


qs use a option for the Array decode:

qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
// 'a=b&a=c'

@ljharb
Copy link
Collaborator

ljharb commented Aug 11, 2023

I get an empty string in node for url.format({message:['value1','value2']}) in every version i can test, including this package. Do you have different repro code?

@irfanhanfi
Copy link

I have the same issue @binggo8322

You can see both versions have different output on the browser -

codepen.io

import * as url from "https://cdn.skypack.dev/url@0.11.1";
import * as url2 from "https://cdn.skypack.dev/url@0.11.0";

const query = {message:['value1','value2']}

const data = {
    protocol: window.location.protocol,
    host: window.location.host,
    pathname: 'test',
    query,
  }
console.log({
  url: url.format(data),
  url2: url2.format(data)
});

Output is -

{
  "url": "https://cdpn.io/test?message%5B0%5D=value1&message%5B1%5D=value2",
  "url2": "https://cdpn.io/test?message=value1&message=value2"
}

When we run this as a test on Cli it gives the identical results on both versions that is -

"https://cdpn.io/test?message=value1&message=value2"

@ljharb
Copy link
Collaborator

ljharb commented Sep 8, 2023

@irfanhanfi ah ok, with that full example, in latest node, all the way down to node 0.5, i get ?message=value1&message=value2 for the query string, which suggests that this library has a bug.

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

No branches or pull requests

3 participants