mrhenry / polyfill-library

MIT License
4 stars 0 forks source link

`URL` polyfill does not throw for invalid input #53

Closed mhassan1 closed 1 month ago

mhassan1 commented 1 month ago

The existing URL polyfill does not throw for invalid input when it should; for example, all of these should throw:

new URL()
new URL('')
new URL('/hello')

This issue was raised previously (https://github.com/JakeChampion/polyfill-library/issues/462), but it was never resolved, and there was a PR (https://github.com/JakeChampion/polyfill-library/pull/627) that was closed without comment.

There seem to be a bunch of existing URL polyfills out there, so maybe we should switch to a different one.

mhassan1 commented 1 month ago

I've looked around at a few other URL polyfills:

romainmenke commented 1 month ago

If we switch to a different polyfill, then my preference would be to use https://www.npmjs.com/package/whatwg-url

The contributors there are also browser implementers, I trust them more to get this right.

Can we handle transpiling?

zloirock commented 1 month ago

npmjs.com/package/core-js-url-browser - lots of tests fail

Could you write specific issues with it?

mhassan1 commented 1 month ago

@zloirock Here's an example of a failing test:

[...new URLSearchParams('?%C2').keys()][0]
// core-js -> "%C2"
// native -> "�"
romainmenke commented 1 month ago

Is that with core-js itself or with the npmjs.com/package/core-js-url-browser npm package? (that package seems archived/deprecated?)

zloirock commented 1 month ago

@mhassan1 yes, I know that core-js has some specific issues with URL, mainly encoding specific, like https://github.com/zloirock/core-js/issues/1223, and the feature detection relaxed to forgive some engines bugs. I mean the list of failing tests that could help to fix it.

mhassan1 commented 1 month ago

@romainmenke That's with core-js; for example, in Node.js:

delete global.URLSearchParams;
var URLSearchParams = require('core-js/web/url-search-params');
[...new URLSearchParams('?%C2').keys()][0];
// -> "%C2"

@zloirock Here's the list of failing tests: