fix(facade): use base element to get base href
Previously, calls to getBaseHref used document.baseURI, which defaults to the current path in the absence of a base element in the document. This leads to surprising behavior. With this change, getBaseHref returns null when a base element is not present in the document.
This commit is contained in:
parent
3df8363a94
commit
8296dcec09
|
@ -342,8 +342,11 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
return window.location;
|
||||
}
|
||||
getBaseHref() {
|
||||
var uri = document.baseUri;
|
||||
var baseUri = Uri.parse(uri);
|
||||
var href = getBaseElementHref();
|
||||
if (href == null) {
|
||||
return null;
|
||||
}
|
||||
var baseUri = Uri.parse(href);
|
||||
return baseUri.path;
|
||||
}
|
||||
String getUserAgent() {
|
||||
|
@ -360,3 +363,15 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
js.context[name] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var baseElement = null;
|
||||
String getBaseElementHref() {
|
||||
if (baseElement == null) {
|
||||
baseElement = document.querySelector('base');
|
||||
if (baseElement == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return baseElement.getAttribute('href');
|
||||
}
|
||||
|
|
|
@ -263,7 +263,13 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
}
|
||||
getHistory(): History { return window.history; }
|
||||
getLocation(): Location { return window.location; }
|
||||
getBaseHref(): string { return relativePath(document.baseURI); }
|
||||
getBaseHref(): string {
|
||||
var href = getBaseElementHref();
|
||||
if (isBlank(href)) {
|
||||
return null;
|
||||
}
|
||||
return relativePath(href);
|
||||
}
|
||||
getUserAgent(): string { return window.navigator.userAgent; }
|
||||
setData(element, name: string, value: string) { element.dataset[name] = value; }
|
||||
getData(element, name: string): string { return element.dataset[name]; }
|
||||
|
@ -271,6 +277,18 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
|
|||
setGlobalVar(name: string, value: any) { global[name] = value; }
|
||||
}
|
||||
|
||||
|
||||
var baseElement = null;
|
||||
function getBaseElementHref(): string {
|
||||
if (isBlank(baseElement)) {
|
||||
baseElement = document.querySelector('base');
|
||||
if (isBlank(baseElement)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return baseElement.attr('href');
|
||||
}
|
||||
|
||||
// based on urlUtils.js in AngularJS 1
|
||||
var urlParsingNode = null;
|
||||
function relativePath(url): string {
|
||||
|
|
Loading…
Reference in New Issue