fix(router): throw when reserved characters used in route definition

Closes #3021
This commit is contained in:
Brian Ford
2015-07-17 02:01:34 -07:00
parent 573c047d50
commit c6409cb624
2 changed files with 31 additions and 0 deletions

View File

@ -178,6 +178,18 @@ function splitBySlash(url: string): List<string> {
return url.split('/');
}
var RESERVED_CHARS = RegExpWrapper.create('//|\\(|\\)|;|\\?|=');
function assertPath(path: string) {
if (StringWrapper.contains(path, '#')) {
throw new BaseException(
`Path "${path}" should not include "#". Use "HashLocationStrategy" instead.`);
}
var illegalCharacter = RegExpWrapper.firstMatch(RESERVED_CHARS, path);
if (isPresent(illegalCharacter)) {
throw new BaseException(
`Path "${path}" contains "${illegalCharacter[0]}" which is not allowed in a route config.`);
}
}
// represents something like '/foo/:bar'
export class PathRecognizer {
@ -187,6 +199,7 @@ export class PathRecognizer {
terminal: boolean = true;
constructor(public path: string, public handler: RouteHandler) {
assertPath(path);
var parsed = parsePathString(path);
var specificity = parsed['specificity'];
var segments = parsed['segments'];