Skip to content

Instantly share code, notes, and snippets.

@rolinh
Last active October 4, 2016 08:19
Show Gist options
  • Save rolinh/ba39c45b718cbd44f5f91af69b588c83 to your computer and use it in GitHub Desktop.
Save rolinh/ba39c45b718cbd44f5f91af69b588c83 to your computer and use it in GitHub Desktop.
nodejs url.resolve() bug
> var url = require("url");
undefined
> var u = url.parse("https://foo.tld");
undefined
> u
Url {
protocol: 'https:',
slashes: true,
auth: null,
host: 'foo.tld',
port: null,
hostname: 'foo.tld',
hash: null,
search: null,
query: null,
pathname: '/',
path: '/',
href: 'https://foo.tld/' }
> var v = url.parse("wss://foo.tld");
undefined
> v
Url {
protocol: 'wss:',
slashes: true,
auth: null,
host: 'foo.tld',
port: null,
hostname: 'foo.tld',
hash: null,
search: null,
query: null,
pathname: null,
path: null,
href: 'wss://foo.tld' }
> url.format(u);
'https://foo.tld/'
> url.format(v);
'wss://foo.tld'
> url.resolve(url.format(u), 'bar');
'https://foo.tld/bar'
> url.resolve(url.format(v), 'bar');
'wss://bar'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment