defunctzombie / node-url

node.js core url module as a module
MIT License
375 stars 96 forks source link

Bug with url.format and object contain array #65

Closed binggo8322 closed 10 months ago

binggo8322 commented 11 months ago

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 commented 11 months ago

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 commented 10 months ago

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 commented 10 months ago

@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.