Skip to content

Commit

Permalink
Fix parseURL in Internet Explorer
Browse files Browse the repository at this point in the history
I added various workarounds to make the tests pass in IE11.

closes pretenderjs#151
  • Loading branch information
dwickern committed Sep 29, 2016
1 parent 619fe0f commit 8ae116a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions pretender.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,30 @@ function parseURL(url) {
// TODO: something for when document isn't present... #yolo
var anchor = document.createElement('a');
anchor.href = url;
anchor.fullpath = anchor.pathname + (anchor.search || '') + (anchor.hash || '');
return anchor;

if (!anchor.host) {
anchor.href = anchor.href; // IE: load the host and protocol
}

var pathname = anchor.pathname;
if (pathname.charAt(0) !== '/') {
pathname = '/' + pathname; // IE: prepend leading slash
}

var host = anchor.host;
if (anchor.port === '80' || anchor.port === '443') {
host = anchor.hostname; // IE: remove default port
}

return {
host: host,
protocol: anchor.protocol,
search: anchor.search,
hash: anchor.hash,
href: anchor.href,
pathname: pathname,
fullpath: pathname + (anchor.search || '') + (anchor.hash || '')
};
}


Expand Down

0 comments on commit 8ae116a

Please sign in to comment.