From 9dc1d6ae810c59243cd083d319ad1c8e19830d03 Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Mon, 14 Sep 2015 15:14:09 -0700 Subject: [PATCH] fix(code size): do not rely on Uri in BrowserDomAdapter Closes #4182 --- .../angular2/src/core/dom/browser_adapter.dart | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/angular2/src/core/dom/browser_adapter.dart b/modules/angular2/src/core/dom/browser_adapter.dart index 6a2cbc24d1..6837a8cf6b 100644 --- a/modules/angular2/src/core/dom/browser_adapter.dart +++ b/modules/angular2/src/core/dom/browser_adapter.dart @@ -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}'; +}