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

[IE] Port is resolved to 80 when unspecified #5

Open
idiotWu opened this issue Jun 5, 2017 · 3 comments
Open

[IE] Port is resolved to 80 when unspecified #5

idiotWu opened this issue Jun 5, 2017 · 3 comments

Comments

@idiotWu
Copy link

idiotWu commented Jun 5, 2017

Input:

new URL('http://a.com')

Output:

{
  ...
  href: 'http://a.com/',
  origin: 'http://a.com:80',
  port: '80',
  ...
}

Expected (as is in Chrome):

{
  ...
  href: 'http://a.com/',
  origin: 'http://a.com',
  port: '',
  ...
}

Edit: this consequence seems to occur in IE only :/

@idiotWu idiotWu changed the title Port is resolved to 80 when unspecified [IE] Port is resolved to 80 when unspecified Jun 5, 2017
@schibsted-martin
Copy link

+1

This library adds default values for things that are not given so validation based on this library will be troublesome. Instead of creating a new issue I will just add one here.

When I do new URL('something') on IE 11 it will accept that as a valid input for the constructor; which on all other browsers (and according to spec I believe) should not - and instead throw an error.

Is this something that we can have a fix for or is there another library we can use as a polyfill? whatwg-url, universal-url etc. all seems to not provide polyfills.

@lifaon74
Copy link
Owner

This lib is a trade-off between size, speed and compliance. I wrote here the full polyfill for nodejs: https://github.com/lifaon74/whatwg-url. The final size is 272Ko which is too much for a polyfill, but not for a server. You can use this library (url-polyfill) safely in 99% of the cases (but for example doesn't include puny codes, some unicode chars, etc...). For specific usage you could probably use this lib with the conjunction of regexp

@schibsted-martin
Copy link

I understand. But adding this RegExp in the constructor of this lib, just throwing an exception if the input is wrong would make it so much cleaner. If I have to add this code in every project I have with this polyfill it will create a river of mess where I sometimes use URL and sometimes will use a mix of it.

Just validating the constructor if it is IE and throwing an exception would really not add much to the size either. And then it would be close to perfect in terms of compliance too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants