fix(code size): do not rely on Uri in BrowserDomAdapter

Closes #4182
This commit is contained in:
Yegor Jbanov 2015-09-14 15:14:09 -07:00 committed by Yegor
parent e4f94f0678
commit 9dc1d6ae81
1 changed files with 13 additions and 3 deletions

View File

@ -426,13 +426,12 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
return window.location;
}
getBaseHref() {
String getBaseHref() {
var href = getBaseElementHref();
if (href == null) {
return null;
}
var baseUri = Uri.parse(href);
return baseUri.path[0] == '/' ? baseUri.path : ('/' + baseUri.path);
return _relativePath(href);
}
resetBaseElement() {
@ -487,3 +486,14 @@ String getBaseElementHref() {
}
return baseElement.getAttribute('href');
}
// based on urlUtils.js in AngularJS 1
AnchorElement _urlParsingNode = null;
String _relativePath(String url) {
if (_urlParsingNode == null) {
_urlParsingNode = new AnchorElement();
}
_urlParsingNode.href = url;
var pathname = _urlParsingNode.pathname;
return (pathname[0] == '/') ? pathname : '/${pathname}';
}