superagent icon indicating copy to clipboard operation
superagent copied to clipboard

fix: ipv6 addresses parsing

Open perrin4869 opened this issue 1 year ago • 3 comments

https://github.com/ladjs/superagent/pull/1803 broke the parsing of ipv6 addresses such as http://[::]:80. Before that PR, using node:url, we would get:

> const { parse } = require("node:url")
undefined
> parse("http://[::]:80")
Url {
  protocol: 'http:',
  slashes: true,
  auth: null,
  host: '[::]:80',
  port: '80',
  hostname: '::',
  hash: null,
  search: null,
  query: null,
  pathname: '/',
  path: '/',
  href: 'http://[::]:80/'
}

With the URL class, however, the hostname becomes:

> new URL("http://[::]:80")
URL {
  href: 'http://[::]/',
  origin: 'http://[::]',
  protocol: 'http:',
  username: '',
  password: '',
  host: '[::]',
  hostname: '[::]',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

This hostname [::] is not compatible with the http.request function. I added some normalization functionality here to return the previous behavior.

Edit: hm... it is a bit hard to add regression tests here, since all the tests seem to run against a single server that doesn't seem to listen on [::]

perrin4869 avatar May 13 '24 17:05 perrin4869

Can confirm. This broke in 9.0.2 .

gramakri avatar Jun 10 '24 09:06 gramakri

If you can get the tests to pass I can merge

titanism avatar Jun 10 '24 19:06 titanism

ok, I managed to add some regression tests! they don't seem to work on http2 so I disabled those

perrin4869 avatar Jun 11 '24 01:06 perrin4869

@titanism any chance we can get this in? Thanks!

perrin4869 avatar Mar 10 '25 02:03 perrin4869

any idea why they don't work in HTTP/2? would be great to have that covered too

titanism avatar Mar 10 '25 12:03 titanism

ok, I figured it out, will send a follow up PR :)

perrin4869 avatar Mar 10 '25 15:03 perrin4869

https://github.com/ladjs/superagent/releases/tag/v10.2.0 released to npm v10.2.0

thanks many 🙏

our OSS efforts are provided via our service https://forwardemail.net 🚀

titanism avatar Mar 11 '25 23:03 titanism