Skip to content

Inconsistency between new URL behavior in Nodejs and browser #30223

Closed
@schalkneethling

Description

@schalkneethling
  • Version:

Node 12.10.0

  • Platform:

macOS 64bit

  • Subsystem:

When using new URL in Nodejs the result of passing an invalid URL to the constructor is inconsistent with the result returned by the same call inside the browser. For example(where url == https://<script></script>:

try {
  let websiteURL = new URL(url);
} catch (error) {
  console.error(err);
}

running the above in browser devtools return the following expected result:

TypeError: https://<script></script> is not a valid URL.

Running the same in Nodejs, returns the following:

URL {
  href: 'https://<script></script%3E',
  origin: 'https://<script><',
  protocol: 'https:',
  username: '',
  password: '',
  host: '<script><',
  hostname: '<script><',
  port: '',
  pathname: '/script%3E',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    whatwg-urlIssues and PRs related to the WHATWG URL implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions