fix(Router): Query strings are copied for HashLocationStrategy
b/27210802 P1 Closes #7298
This commit is contained in:
parent
ebd438ff5e
commit
b47f80ec76
|
@ -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 {
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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); }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue