From cdc7b03e67818a7b4f8dc98f32a7a84c402c7b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Fri, 12 Jun 2015 12:57:35 -0700 Subject: [PATCH] fix(router): avoid two slash values between the baseHref and the path --- modules/angular2/src/router/location.ts | 3 +++ modules/angular2/test/router/location_spec.ts | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/modules/angular2/src/router/location.ts b/modules/angular2/src/router/location.ts index 5f1ae15a5f..38d1cf12b7 100644 --- a/modules/angular2/src/router/location.ts +++ b/modules/angular2/src/router/location.ts @@ -62,5 +62,8 @@ function stripIndexHtml(url: string): string { if (url.length > 10 && StringWrapper.substring(url, url.length - 11) == '/index.html') { return StringWrapper.substring(url, 0, url.length - 11); } + if (url.length > 1 && url[url.length - 1] == '/') { + url = StringWrapper.substring(url, 0, url.length - 1); + } return url; } diff --git a/modules/angular2/test/router/location_spec.ts b/modules/angular2/test/router/location_spec.ts index 4475d8e06f..043ac2027d 100644 --- a/modules/angular2/test/router/location_spec.ts +++ b/modules/angular2/test/router/location_spec.ts @@ -38,6 +38,14 @@ export function main() { it('should not prepend urls with starting slash when an empty URL is provided', () => { expect(location.normalizeAbsolutely('')).toEqual(browserLocation.baseHref); }); + it('should not prepend path with an extra slash when a baseHref has a trailing slash', () => { + browserLocation = new DummyBrowserLocation(); + browserLocation.spy('pushState'); + browserLocation.baseHref = '/my/slashed/app/'; + location = new Location(browserLocation); + expect(location.normalizeAbsolutely('/page')).toEqual('/my/slashed/app/page'); + }); + it('should not append urls with leading slash on navigate', () => { location.go('/my/app/user/btford'); expect(browserLocation.spy('pushState'))