unshiftio / url-parse

Small footprint URL parser that works seamlessly across Node.js and browser environments.
http://unshift.io
MIT License
1.03k stars 104 forks source link

Query params with the same name should be returned as an array #202

Closed Flackus closed 3 years ago

Flackus commented 3 years ago

Version

1.5.1

Test

const parse = require('url-parse');
console.log(parse("https://example.com/?token=1&token=2", true));

Current result:

{
  slashes: true,
  protocol: 'https:',
  hash: '',
  query: { token: '1' },
  pathname: '/',
  auth: '',
  host: 'example.com',
  port: '',
  hostname: 'example.com',
  password: '',
  username: '',
  origin: 'https://example.com',
  href: 'https://example.com/?token=1'
}

Expected result:

{
  slashes: true,
  protocol: 'https:',
  hash: '',
  query: { token: ['1', '2'] },
  pathname: '/',
  auth: '',
  host: 'example.com',
  port: '',
  hostname: 'example.com',
  password: '',
  username: '',
  origin: 'https://example.com',
  href: 'https://example.com/?token=1&token=2'
}
lpinca commented 3 years ago

This is expected. See https://github.com/unshiftio/querystringify/issues/32, https://github.com/unshiftio/querystringify/issues/23, and https://github.com/unshiftio/querystringify/issues/15.

You can use a custom query string parser if you want. See https://github.com/unshiftio/url-parse#usage.

lpinca commented 3 years ago

I'm closing this as answered. Discussion can continue if needed.

Flackus commented 3 years ago

Thanks for the explanation! :)