Skip to content

Commit

Permalink
force href to refresh when base is present on IE
Browse files Browse the repository at this point in the history
  • Loading branch information
vrichard committed May 2, 2017
1 parent 3db0ee3 commit a73dcf5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "url-polyfill",
"version": "1.0.4",
"version": "1.0.5",
"description": "Polyfill URL and URLSearchParams",
"main": "url-polyfill.js",
"scripts": {
Expand Down
15 changes: 15 additions & 0 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,21 @@ test.describe('URL polyfill', function() {
})*/;
});

test.it('Test URL with base', () => {
return tester.executeScript(driver, `
var url = new URL('test', 'http://www.example.com');
if(url.host !== 'www.example.com') throw new Error('Invalid host : ' + url.host);
if(url.hostname !== 'www.example.com') throw new Error('Invalid hostname : ' + url.hostname);
if(url.href !== 'http://www.example.com/test') throw new Error('Invalid href : ' + url.href);
if(url.pathname !== '/test') throw new Error('Invalid pathname : ' + url.pathname);
if(url.protocol !== 'http:') throw new Error('Invalid protocol : ' + url.protocol);
if(url.search !== '') throw new Error('Invalid search : ' + url.search);
return url;
`);
});


test.after(() => {
driver.quit();
Expand Down
2 changes: 2 additions & 0 deletions url-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ var g = (typeof global !== 'undefined') ? global :
if(typeof url !== 'string') throw new TypeError('Failed to construct \'URL\': Invalid URL');

var doc = document.implementation.createHTMLDocument('');
window.doc = doc;
if(base) {
var baseElement = doc.createElement('base');
baseElement.href = base;
Expand All @@ -181,6 +182,7 @@ var g = (typeof global !== 'undefined') ? global :
var anchorElement = doc.createElement('a');
anchorElement.href = url;
doc.body.appendChild(anchorElement);
anchorElement.href = anchorElement.href; // force href to refresh

if(anchorElement.protocol === ':' || !/:/.test(anchorElement.href)) {
throw new TypeError('Invalid URL');
Expand Down
2 changes: 1 addition & 1 deletion url-polyfill.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a73dcf5

Please sign in to comment.