Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL: Constructor should throw error if URL cannot be parsed #462

Open
aduth opened this issue Feb 11, 2020 · 1 comment
Open

URL: Constructor should throw error if URL cannot be parsed #462

aduth opened this issue Feb 11, 2020 · 1 comment
Assignees
Labels
bug Something isn't working library Relates to an Origami library

Comments

@aduth
Copy link

aduth commented Feb 11, 2020

[type]: Bug report

What

The URL polyfill constructor should throw an error if passed an invalid URL.

new URL( 'invalid' );
// Expected: Uncaught TypeError: Failed to construct 'URL': Invalid URL
// Actual: (successfully returns new instance of URL)

For context, this affects us in that we use the throwing of an error as an indication of whether a given URL is a valid URL. Thus, without a thrown error, invalid URLs would be incorrectly reported as being valid when the polyfill is used.

https://github.com/WordPress/gutenberg/blob/59d7463/packages/url/src/is-url.js

(Related originating conversation: WordPress/gutenberg#20172 (comment))

Details

References:

If the given base URL or the resulting URL are not valid URLs, the JavaScript TypeError exception is thrown.

https://developer.mozilla.org/en-US/docs/Web/API/URL/URL

If parsedURL is failure, then throw a TypeError.

https://url.spec.whatwg.org/#dom-url-url

Other Implementations:

Relevant Code:

https://github.com/Financial-Times/polyfill-library/blob/5360b0dd924cc08ca1a815e003033c7e489c7ab0/polyfills/URL/polyfill.js#L284-L452

@JakeChampion
Copy link
Owner

PR for this work --> #627

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working library Relates to an Origami library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants