From 6e0ca7f39aee4f6d281579db7fccd7f825bacd14 Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Mon, 21 Sep 2015 12:05:34 -0700 Subject: [PATCH] fix(router): use StringWrapper.startsWith --- modules/angular2/src/router/route_recognizer.ts | 7 ++++--- modules/angular2/src/router/url_parser.ts | 12 +++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/modules/angular2/src/router/route_recognizer.ts b/modules/angular2/src/router/route_recognizer.ts index d63bbf8079..e3af241502 100644 --- a/modules/angular2/src/router/route_recognizer.ts +++ b/modules/angular2/src/router/route_recognizer.ts @@ -52,7 +52,8 @@ export class RouteRecognizer { if (config instanceof AuxRoute) { handler = new SyncRouteHandler(config.component, config.data); - let path = config.path.startsWith('/') ? config.path.substring(1) : config.path; + let path = + StringWrapper.startsWith(config.path, '/') ? config.path.substring(1) : config.path; var recognizer = new PathRecognizer(config.path, handler); this.auxRoutes.set(path, recognizer); return recognizer.terminal; @@ -140,11 +141,11 @@ export class Redirector { toSegments: string[] = []; constructor(path: string, redirectTo: string) { - if (path.startsWith('/')) { + if (StringWrapper.startsWith(path, '/')) { path = path.substring(1); } this.segments = path.split('/'); - if (redirectTo.startsWith('/')) { + if (StringWrapper.startsWith(redirectTo, '/')) { redirectTo = redirectTo.substring(1); } this.toSegments = redirectTo.split('/'); diff --git a/modules/angular2/src/router/url_parser.ts b/modules/angular2/src/router/url_parser.ts index b1f71e8a30..a09f38ecdf 100644 --- a/modules/angular2/src/router/url_parser.ts +++ b/modules/angular2/src/router/url_parser.ts @@ -1,5 +1,11 @@ import {StringMap, StringMapWrapper} from 'angular2/src/core/facade/collection'; -import {isPresent, isBlank, RegExpWrapper, CONST_EXPR} from 'angular2/src/core/facade/lang'; +import { + isPresent, + isBlank, + StringWrapper, + RegExpWrapper, + CONST_EXPR +} from 'angular2/src/core/facade/lang'; import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions'; /** @@ -71,10 +77,10 @@ function matchUrlSegment(str: string): string { export class UrlParser { private _remaining: string; - peekStartsWith(str: string): boolean { return this._remaining.startsWith(str); } + peekStartsWith(str: string): boolean { return StringWrapper.startsWith(this._remaining, str); } capture(str: string): void { - if (!this._remaining.startsWith(str)) { + if (!StringWrapper.startsWith(this._remaining, str)) { throw new BaseException(`Expected "${str}".`); } this._remaining = this._remaining.substring(str.length);