Skip to content

Commit

Permalink
fix: Router.go string pathname parsing in IE
Browse files Browse the repository at this point in the history
  • Loading branch information
platosha committed Oct 4, 2019
1 parent 63ee8d6 commit 25de7b9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@
"column": 2
},
"end": {
"line": 2263,
"line": 2264,
"column": 3
}
},
Expand Down Expand Up @@ -1417,7 +1417,7 @@
"column": 0
},
"end": {
"line": 2264,
"line": 2265,
"column": 1
}
},
Expand Down
4 changes: 2 additions & 2 deletions docs/vaadin-router/analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@
"column": 2
},
"end": {
"line": 2263,
"line": 2264,
"column": 3
}
},
Expand Down Expand Up @@ -1417,7 +1417,7 @@
"column": 0
},
"end": {
"line": 2264,
"line": 2265,
"column": 1
}
},
Expand Down
4 changes: 2 additions & 2 deletions docs/vaadin-router/demo/demo-shell.html
Original file line number Diff line number Diff line change
Expand Up @@ -7259,7 +7259,7 @@
* string property, and optional `search` and `hash` string properties.
* @return {boolean}
*/}],[{key:"setTriggers",value:function setTriggers(){for(var _len=arguments.length,triggers=Array(_len),_key=0;_key<_len;_key++){triggers[_key]=arguments[_key]}setNavigationTriggers(triggers)}},{key:"go",value:function go(path){var _ref4=isString(path)?this.__createUrl(path,"http://a")// some base to omit origin
:path,pathname=_ref4.pathname,search=_ref4.search,hash=_ref4.hash;return fireRouterEvent("go",{pathname:pathname,search:search,hash:hash})}}]);return Router}(Resolver),DEV_MODE_CODE_REGEXP=/\/\*\*\s+vaadin-dev-mode:start([\s\S]*)vaadin-dev-mode:end\s+\*\*\//i,FlowClients=window.Vaadin&&window.Vaadin.Flow&&window.Vaadin.Flow.clients;function isMinified(){function test(){/** vaadin-dev-mode:start
:path,pathname=_ref4.pathname,search=_ref4.search,hash=_ref4.hash;console.log(path,pathname,search,hash);return fireRouterEvent("go",{pathname:pathname,search:search,hash:hash})}}]);return Router}(Resolver),DEV_MODE_CODE_REGEXP=/\/\*\*\s+vaadin-dev-mode:start([\s\S]*)vaadin-dev-mode:end\s+\*\*\//i,FlowClients=window.Vaadin&&window.Vaadin.Flow&&window.Vaadin.Flow.clients;function isMinified(){function test(){/** vaadin-dev-mode:start
return false;
vaadin-dev-mode:end **/return!0}return uncommentAndRun(test)}function isDevelopmentMode(){try{if(isForcedDevelopmentMode()){return!0}if(!isLocalhost()){return!1}if(FlowClients){return!isFlowProductionMode()}return!isMinified()}catch(e){// Some error in this code, assume production so no further actions will be taken
return!1}}function isForcedDevelopmentMode(){return localStorage.getItem("vaadin.developmentmode.force")}function isLocalhost(){return 0<=["localhost","127.0.0.1"].indexOf(window.location.hostname)}function isFlowProductionMode(){if(FlowClients){var productionModeApps=Object.keys(FlowClients).map(function(key){return FlowClients[key]}).filter(function(client){return client.productionMode});if(0<productionModeApps.length){return!0}}return!1}function uncommentAndRun(callback,args){if("function"!==typeof callback){return}var match=DEV_MODE_CODE_REGEXP.exec(callback.toString());if(match){try{// requires CSP: script-src 'unsafe-eval'
Expand Down Expand Up @@ -7718,7 +7718,7 @@
Object.defineProperty(urlAnchor,"origin",{get:function get(){// IE11: on HTTP and HTTPS the default port is not included into
// window.location.origin, so won't include it here either.
var protocol=urlAnchor.protocol,port=urlAnchor.port,defaultHttp="http:"===protocol&&"80"===port,defaultHttps="https:"===protocol&&"443"===port,host=defaultHttp||defaultHttps?urlAnchor.hostname:urlAnchor.host;return"".concat(protocol,"//").concat(host)}});// IE11: HTMLAnchorElement pathname does not start with a leading slash
Object.defineProperty(urlAnchor,"pathname",{get:function get(){return urlAnchor.href.slice(urlAnchor.origin.length)}})}}}};Resolver.__createUrl=function(path,base){Resolver.__ensureUrlAvailableOrPolyfilled();if(isUrlAvailable){return new URL(path,base)}urlBase.href=base;urlAnchor.href=path.replace(/ /g,"%20");// IE11: only absolute href setting results in correct part properties
var getPathnameOrig=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(urlAnchor),"pathname").get;Object.defineProperty(urlAnchor,"pathname",{get:function get(){var pathname=getPathnameOrig.apply(urlAnchor);return"/"!==pathname.charAt(0)?"/"+pathname:pathname}})}}}};Resolver.__createUrl=function(path,base){Resolver.__ensureUrlAvailableOrPolyfilled();if(isUrlAvailable){return new URL(path,base)}urlBase.href=base;urlAnchor.href=path.replace(/ /g,"%20");// IE11: only absolute href setting results in correct part properties
// (`protocol`, `host`, `port`, and such), otherwise they are empty.
urlAnchor.href=urlAnchor.href;// eslint-disable-line no-self-assign
return urlAnchor};exports.Resolver=Resolver;exports.Router=Router;Object.defineProperty(exports,"__esModule",{value:!0})});//# sourceMappingURL=vaadin-router.umd.js.map</script><script>// In order to make the demos work without the import statement there
Expand Down
9 changes: 8 additions & 1 deletion index.polyfilled.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,16 @@ Resolver.__ensureUrlAvailableOrPolyfilled = () => {
});

// IE11: HTMLAnchorElement pathname does not start with a leading slash
const getPathnameOrig = Object.getOwnPropertyDescriptor(
Object.getPrototypeOf(urlAnchor),
'pathname'
).get;
Object.defineProperty(urlAnchor, 'pathname', {
get: () => {
return urlAnchor.href.slice(urlAnchor.origin.length);
const pathname = getPathnameOrig.apply(urlAnchor);
return pathname.charAt(0) !== '/'
? '/' + pathname
: pathname;
}
});
}
Expand Down
1 change: 1 addition & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,7 @@ export class Router extends Resolver {
const {pathname, search, hash} = isString(path)
? this.__createUrl(path, 'http://a') // some base to omit origin
: path;
console.log(path, pathname, search, hash);
return fireRouterEvent('go', {pathname, search, hash});
}
}

0 comments on commit 25de7b9

Please sign in to comment.