Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
2 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,14 +263,32 @@ 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]; } | ||
// TODO(tbosch): move this into a separate environment class once we have it | ||
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'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
markharding
|
||
} | ||
|
||
// based on urlUtils.js in AngularJS 1 | ||
var urlParsingNode = null; | ||
function relativePath(url): string { | ||
|
You might have mixed dart and ts. You can either use
baseElement.href
orbaseElement.getAttribute('href')
since this throws an errorTypeError: baseElement.attr is not a function