X Tutup
Skip to content

Commit b47f80e

Browse files
committed
fix(Router): Query strings are copied for HashLocationStrategy
b/27210802 P1 Closes angular#7298
1 parent ebd438f commit b47f80e

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

modules/angular2/src/router/hash_location_strategy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ export class HashLocationStrategy extends LocationStrategy {
6969
// the hash value is always prefixed with a `#`
7070
// and if it is empty then it will stay empty
7171
var path = this._platformLocation.hash;
72+
if (!isPresent(path)) path = '#';
7273

7374
// Dart will complain if a call to substring is
7475
// executed with a position value that extends the
7576
// length of string.
76-
return (path.length > 0 ? path.substring(1) : path) +
77-
normalizeQueryParams(this._platformLocation.search);
77+
return (path.length > 0 ? path.substring(1) : path);
7878
}
7979

8080
prepareExternalUrl(internal: string): string {

modules/angular2/test/router/hash_location_strategy_spec.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ import {
1313
} from 'angular2/testing_internal';
1414

1515
import {Injector, provide} from 'angular2/core';
16-
import {CONST_EXPR} from 'angular2/src/facade/lang';
1716

1817
import {PlatformLocation} from 'angular2/src/router/platform_location';
19-
import {LocationStrategy, APP_BASE_HREF} from 'angular2/src/router/location_strategy';
18+
import {APP_BASE_HREF} from 'angular2/src/router/location_strategy';
2019
import {HashLocationStrategy} from 'angular2/src/router/hash_location_strategy';
2120
import {SpyPlatformLocation} from './spies';
2221

2322
export function main() {
2423
describe('HashLocationStrategy', () => {
25-
var platformLocation, locationStrategy;
24+
var platformLocation: SpyPlatformLocation;
25+
var locationStrategy: HashLocationStrategy;
2626

2727
beforeEachProviders(
2828
() => [HashLocationStrategy, provide(PlatformLocation, {useClass: SpyPlatformLocation})]);
@@ -163,5 +163,25 @@ export function main() {
163163
expect(platformLocation.spy('pushState')).toHaveBeenCalledWith(null, 'Title', '#/app/');
164164
});
165165
});
166+
167+
describe('hashLocationStrategy bugs', () => {
168+
beforeEach(inject([PlatformLocation, HashLocationStrategy], (pl, ls) => {
169+
platformLocation = pl;
170+
locationStrategy = ls;
171+
platformLocation.spy('pushState');
172+
platformLocation.pathname = '';
173+
}));
174+
175+
it('should not include platform search', () => {
176+
platformLocation.search = '?donotinclude';
177+
expect(locationStrategy.path()).toEqual('');
178+
});
179+
180+
it('should not include platform search even with hash', () => {
181+
platformLocation.hash = '#hashPath';
182+
platformLocation.search = '?donotinclude';
183+
expect(locationStrategy.path()).toEqual('hashPath');
184+
});
185+
});
166186
});
167187
}

modules/angular2/test/router/spies.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ class SpyRouter extends SpyObject implements Router {}
1313
class SpyRouterOutlet extends SpyObject implements RouterOutlet {}
1414

1515
class SpyPlatformLocation extends SpyObject implements PlatformLocation {
16-
String pathname;
16+
String pathname = null;
17+
String search = null;
18+
String hash = null;
1719
}

modules/angular2/test/router/spies.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,7 @@ export class SpyLocation extends SpyObject {
1515

1616
export class SpyPlatformLocation extends SpyObject {
1717
pathname: string = null;
18+
search: string = null;
19+
hash: string = null;
1820
constructor() { super(SpyPlatformLocation); }
1921
}

0 commit comments

Comments
 (0)
X Tutup