webcomponents / webcomponents/polyfills

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

Open
#241 6 comments 2 reactions 0 assignees View on GitHub
Package: url Type: Feature wontfix
Dominant language
HTML
Stars
1.2k
Forks
168
PR merge metrics
No merged PRs in 30d

Description

### 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`).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.