- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 33.7k
 
Closed
Description
- Version: 
v16.2.0 - Platform: 
Darwin bisterix.local 20.5.0 Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64 - Subsystem: 
url 
What steps will reproduce the bug?
Running new URL('\\\\-', 'http://asd') in Node.js v16.2.0 shell will override the hostname of the arbitrarily chosen base URL.
How often does it reproduce? Is there a required condition?
Every time.
What is the expected behavior?
The URL is correctly constructed and the hostname is preserved:
URL {
  href: 'http://asd///-',
  origin: 'http://asd',
  protocol: 'http:',
  username: '',
  password: '',
  host: 'asd',
  hostname: 'asd',
  port: '',
  pathname: '///-',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}
What do you see instead?
The hostname of the base URL is overridden by the path:
$ node
Welcome to Node.js v16.2.0.
Type ".help" for more information.
> new URL('\\\\-', 'http://asd')
URL {
  href: 'http://-/',
  origin: 'http://-',
  protocol: 'http:',
  username: '',
  password: '',
  host: '-',
  hostname: '-',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}
Additional information
This does not occur in Node.js 14.15.4 (I haven't tested in other versions). Happy to help resolve this, although I would need some pointers for where to start :)
Metadata
Metadata
Assignees
Labels
No labels