Skip to content

URL.href has side effect if parsing errored #24345

Closed
@TimothyGu

Description

@TimothyGu
  • Version: v11.1.0
  • Platform: macOS
  • Subsystem: url

When passing an invalid URL to URL's href setter, the original URL gets destroyed, in contrary to the spec.

> u = new URL('https://example.com/')
URL {
  href: 'https://example.com/',
  origin: 'https://example.com',
  protocol: 'https:',
  username: '',
  password: '',
  host: 'example.com',
  hostname: 'example.com',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: '' }
> u.href = ''
{ TypeError [ERR_INVALID_URL]: Invalid URL: 
    at onParseError (internal/url.js:240:17)
    at parse (internal/url.js:249:3)
    at URL.set [as href] (internal/url.js:447:7) input: '' }
> u
URL {
  href: ':',
  origin: 'null',
  protocol: ':',
  username: '',
  password: '',
  host: '',
  hostname: '',
  port: '',
  pathname: '',
  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