Skip to content

Base URL hostnames are overridden by certain paths when constructing a URL #38963

@jonnydgreen

Description

@jonnydgreen
  • 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions