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

Failed to create URL with base address contained port 80 #49

Open
Eykhler opened this issue Aug 1, 2019 · 2 comments
Open

Failed to create URL with base address contained port 80 #49

Eykhler opened this issue Aug 1, 2019 · 2 comments

Comments

@Eykhler
Copy link

Eykhler commented Aug 1, 2019

Input

new URL('/part', 'http://servername:80/app');

Result in error: 'URL unable to set base http://servername/app due to http://servername:80/app'

Another problem is that the address must be lowercase due to case-sensitive string comparison, i.e. I can not write

new URL('/part', 'http://SERVERNAME/app');
@lifaon74
Copy link
Owner

lifaon74 commented Aug 1, 2019

Well, origin (second argument) should not contain any path. This is an error on your side even if some browsers allows it.
Second, domain name are lower-cased, this is normal behavior...

@Eykhler
Copy link
Author

Eykhler commented Aug 1, 2019

Looking at the https://developer.mozilla.org/en-US/docs/Web/API/URL article and Usage example we see that the base part may not be the origin but any base address:

const url = new URL('../cats', 'http://www.example.com/cats');

Casting a domain name to lowercase before creating URL object is not a problem, but again it will be more convenient to ignore case sensitivity when building URLs

var polyfillURL = function() {
  var _URL = global.URL;

  var URL = function(url, base) {
      if (base && (global.location === void 0 || base !== global.location.href)) {
        ....
        try {
           if (baseElement.href.indexOf(base.toLowerCase()) !== 0) throw new Error(baseElement.href);
        } catch (err) {
          throw new Error('URL unable to set base ' + base + ' due to ' + err);
        }
      }

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

2 participants