X Tutup
Skip to content

Commit 6e0ca7f

Browse files
committed
fix(router): use StringWrapper.startsWith
1 parent 43f97a9 commit 6e0ca7f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

modules/angular2/src/router/route_recognizer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ export class RouteRecognizer {
5252

5353
if (config instanceof AuxRoute) {
5454
handler = new SyncRouteHandler(config.component, config.data);
55-
let path = config.path.startsWith('/') ? config.path.substring(1) : config.path;
55+
let path =
56+
StringWrapper.startsWith(config.path, '/') ? config.path.substring(1) : config.path;
5657
var recognizer = new PathRecognizer(config.path, handler);
5758
this.auxRoutes.set(path, recognizer);
5859
return recognizer.terminal;
@@ -140,11 +141,11 @@ export class Redirector {
140141
toSegments: string[] = [];
141142

142143
constructor(path: string, redirectTo: string) {
143-
if (path.startsWith('/')) {
144+
if (StringWrapper.startsWith(path, '/')) {
144145
path = path.substring(1);
145146
}
146147
this.segments = path.split('/');
147-
if (redirectTo.startsWith('/')) {
148+
if (StringWrapper.startsWith(redirectTo, '/')) {
148149
redirectTo = redirectTo.substring(1);
149150
}
150151
this.toSegments = redirectTo.split('/');

modules/angular2/src/router/url_parser.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import {StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection';
2-
import {isPresent, isBlank, RegExpWrapper, CONST_EXPR} from 'angular2/src/core/facade/lang';
2+
import {
3+
isPresent,
4+
isBlank,
5+
StringWrapper,
6+
RegExpWrapper,
7+
CONST_EXPR
8+
} from 'angular2/src/core/facade/lang';
39
import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions';
410

511
/**
@@ -71,10 +77,10 @@ function matchUrlSegment(str: string): string {
7177
export class UrlParser {
7278
private _remaining: string;
7379

74-
peekStartsWith(str: string): boolean { return this._remaining.startsWith(str); }
80+
peekStartsWith(str: string): boolean { return StringWrapper.startsWith(this._remaining, str); }
7581

7682
capture(str: string): void {
77-
if (!this._remaining.startsWith(str)) {
83+
if (!StringWrapper.startsWith(this._remaining, str)) {
7884
throw new BaseException(`Expected "${str}".`);
7985
}
8086
this._remaining = this._remaining.substring(str.length);

0 commit comments

Comments
 (0)
X Tutup