diff --git a/modules/angular2/src/router/hash_location_strategy.ts b/modules/angular2/src/router/hash_location_strategy.ts index 937d195d6c..26dd67016d 100644 --- a/modules/angular2/src/router/hash_location_strategy.ts +++ b/modules/angular2/src/router/hash_location_strategy.ts @@ -69,12 +69,12 @@ export class HashLocationStrategy extends LocationStrategy { // the hash value is always prefixed with a `#` // and if it is empty then it will stay empty var path = this._platformLocation.hash; + if (!isPresent(path)) path = '#'; // Dart will complain if a call to substring is // executed with a position value that extends the // length of string. - return (path.length > 0 ? path.substring(1) : path) + - normalizeQueryParams(this._platformLocation.search); + return (path.length > 0 ? path.substring(1) : path); } prepareExternalUrl(internal: string): string { diff --git a/modules/angular2/test/router/hash_location_strategy_spec.ts b/modules/angular2/test/router/hash_location_strategy_spec.ts index e354cccfe0..3b9e56524d 100644 --- a/modules/angular2/test/router/hash_location_strategy_spec.ts +++ b/modules/angular2/test/router/hash_location_strategy_spec.ts @@ -13,16 +13,16 @@ import { } from 'angular2/testing_internal'; import {Injector, provide} from 'angular2/core'; -import {CONST_EXPR} from 'angular2/src/facade/lang'; import {PlatformLocation} from 'angular2/src/router/platform_location'; -import {LocationStrategy, APP_BASE_HREF} from 'angular2/src/router/location_strategy'; +import {APP_BASE_HREF} from 'angular2/src/router/location_strategy'; import {HashLocationStrategy} from 'angular2/src/router/hash_location_strategy'; import {SpyPlatformLocation} from './spies'; export function main() { describe('HashLocationStrategy', () => { - var platformLocation, locationStrategy; + var platformLocation: SpyPlatformLocation; + var locationStrategy: HashLocationStrategy; beforeEachProviders( () => [HashLocationStrategy, provide(PlatformLocation, {useClass: SpyPlatformLocation})]); @@ -163,5 +163,25 @@ export function main() { expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '#/app/'); }); }); + + describe('hashLocationStrategy bugs', () => { + beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => { + platformLocation = pl; + locationStrategy = ls; + platformLocation.spy('pushState'); + platformLocation.pathname = ''; + })); + + it('should not include platform search', () => { + platformLocation.search = '?donotinclude'; + expect(locationStrategy.path()).toEqual(''); + }); + + it('should not include platform search even with hash', () => { + platformLocation.hash = '#hashPath'; + platformLocation.search = '?donotinclude'; + expect(locationStrategy.path()).toEqual('hashPath'); + }); + }); }); } diff --git a/modules/angular2/test/router/spies.dart b/modules/angular2/test/router/spies.dart index af66ea951b..47a45f91bd 100644 --- a/modules/angular2/test/router/spies.dart +++ b/modules/angular2/test/router/spies.dart @@ -13,5 +13,7 @@ class SpyRouter extends SpyObject implements Router {} class SpyRouterOutlet extends SpyObject implements RouterOutlet {} class SpyPlatformLocation extends SpyObject implements PlatformLocation { - String pathname; + String pathname = null; + String search = null; + String hash = null; } diff --git a/modules/angular2/test/router/spies.ts b/modules/angular2/test/router/spies.ts index 81b7f21cb8..a6b2a910fa 100644 --- a/modules/angular2/test/router/spies.ts +++ b/modules/angular2/test/router/spies.ts @@ -15,5 +15,7 @@ export class SpyLocation extends SpyObject { export class SpyPlatformLocation extends SpyObject { pathname: string = null; + search: string = null; + hash: string = null; constructor() { super(SpyPlatformLocation); } }