X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/angular2/src/router/hash_location_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
26 changes: 23 additions & 3 deletions modules/angular2/test/router/hash_location_strategy_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})]);
Expand Down Expand Up @@ -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');
});
});
});
}
4 changes: 3 additions & 1 deletion modules/angular2/test/router/spies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 2 additions & 0 deletions modules/angular2/test/router/spies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
}
X Tutup