Skip to content

Commit

Permalink
Merge pull request #547 from S2-/fix-ie11
Browse files Browse the repository at this point in the history
fix ie11 sameOrigin check on https
  • Loading branch information
matthewp authored Dec 30, 2019
2 parents 0d7e127 + 78c3cb7 commit 95ee431
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,17 +485,25 @@
* @param {string} href
* @api public
*/

Page.prototype.sameOrigin = function(href) {
if(!href || !isLocation) return false;

var url = this._toURL(href);
var window = this._window;

var loc = window.location;

/*
When the port is the default http port 80 for http, or 443 for
https, internet explorer 11 returns an empty string for loc.port,
so we need to compare loc.port with an empty string if url.port
is the default port 80 or 443.
Also the comparition with `port` is changed from `===` to `==` because
`port` can be a string sometimes. This only applies to ie11.
*/
return loc.protocol === url.protocol &&
loc.hostname === url.hostname &&
loc.port === url.port;
(loc.port === url.port || loc.port === '' && (url.port == 80 || url.port == 443)); // jshint ignore:line
};

/**
Expand Down
14 changes: 6 additions & 8 deletions page.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
* Module dependencies.
*/



/**
* Short-cuts for global-object checks
Expand Down Expand Up @@ -885,7 +885,6 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
* @param {string} href
* @api public
*/

Page.prototype.sameOrigin = function(href) {
if(!href || !isLocation) return false;

Expand All @@ -895,13 +894,14 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
var loc = window.location;

/*
when the port is the default http port 80, internet explorer 11
returns an empty string for loc.port, so we need to compare loc.port
with an empty string if url.port is the default port 80.
when the port is the default http port 80 for http, or 443 for
https, internet explorer 11 returns an empty string for loc.port,
so we need to compare loc.port with an empty string if url.port
is the default port 80 or 443.
*/
return loc.protocol === url.protocol &&
loc.hostname === url.hostname &&
(loc.port === url.port || loc.port === '' && url.port === 80);
(loc.port === url.port || loc.port === '' && (url.port == 80 || url.port == 443)); // jshint ignore:line
};

/**
Expand Down Expand Up @@ -1189,8 +1189,6 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
m = this.regexp.exec(decodeURIComponent(pathname));

if (!m) return false;

delete params[0]

for (var i = 1, len = m.length; i < len; ++i) {
var key = keys[i - 1];
Expand Down

0 comments on commit 95ee431

Please sign in to comment.