polyfills icon indicating copy to clipboard operation
polyfills copied to clipboard

[URL] URL polyfill isn't compatible with the spec: doesn't throw on partial URLs

Open sgomes opened this issue 5 years ago • 6 comments

Description

The URL polyfill does not throw an exception on new URL( string ) where string is not an absolute URL and no base URL is provided.

Live Demo

https://jsbin.com/dahuqeqoyu/edit?html,console,output

Steps to Reproduce

  1. Ensure that the URL polyfill is active by e.g. specifying window.forceJURL = true before loading it
  2. Attempt to create a URL object from a partial URL and no base, e.g. new URL('/path')
  3. Observe whether an exception is thrown or not

Expected Results

It's expected that an exception is thrown if a URL string without a scheme is provided and no base is provided, as per https://url.spec.whatwg.org/#no-scheme-state (emphasis mine):

If base is null, or base’s cannot-be-a-base-URL flag is set and c is not U+0023 (#), validation error, return failure.

Modern browsers that implement the spec behave as expected.

Actual Results

An error is not thrown, and instead a URL object is created with most of its properties set to empty strings, and the protocol property set to ":".

Browsers Affected

Any browser in which the polyfill is applied, whether it's because there's no native support for URL (e.g. IE11), or because the polyfill is forced (window.forceJURL = true).

sgomes avatar Dec 13 '19 12:12 sgomes

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 22 '21 12:04 stale[bot]

Adding a note that the polyfill is very much still being used, so it may still be worth it to fix this issue.

sgomes avatar Apr 22 '21 12:04 sgomes

Adding a note that this bug is still present in the latest version, @webcomponents/[email protected].

sgomes avatar Jul 08 '21 11:07 sgomes

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 10 '22 05:07 stale[bot]

@bicknellr Can I create a PR to fix this bug?

xiaoxiangmoe avatar Jul 22 '22 12:07 xiaoxiangmoe

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 12 '23 09:08 stale[bot]