fix(router): throw when reserved characters used in route definition
Closes #3021
This commit is contained in:
parent
573c047d50
commit
c6409cb624
|
@ -178,6 +178,18 @@ function splitBySlash(url: string): List<string> {
|
||||||
return url.split('/');
|
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'
|
// represents something like '/foo/:bar'
|
||||||
export class PathRecognizer {
|
export class PathRecognizer {
|
||||||
|
@ -187,6 +199,7 @@ export class PathRecognizer {
|
||||||
terminal: boolean = true;
|
terminal: boolean = true;
|
||||||
|
|
||||||
constructor(public path: string, public handler: RouteHandler) {
|
constructor(public path: string, public handler: RouteHandler) {
|
||||||
|
assertPath(path);
|
||||||
var parsed = parsePathString(path);
|
var parsed = parsePathString(path);
|
||||||
var specificity = parsed['specificity'];
|
var specificity = parsed['specificity'];
|
||||||
var segments = parsed['segments'];
|
var segments = parsed['segments'];
|
||||||
|
|
|
@ -21,6 +21,24 @@ var mockRouteHandler = new SyncRouteHandler(DummyClass);
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('PathRecognizer', () => {
|
describe('PathRecognizer', () => {
|
||||||
|
|
||||||
|
it('should throw when given an invalid path', () => {
|
||||||
|
expect(() => new PathRecognizer('/hi#', mockRouteHandler))
|
||||||
|
.toThrowError(`Path "/hi#" should not include "#". Use "HashLocationStrategy" instead.`);
|
||||||
|
expect(() => new PathRecognizer('hi?', mockRouteHandler))
|
||||||
|
.toThrowError(`Path "hi?" contains "?" which is not allowed in a route config.`);
|
||||||
|
expect(() => new PathRecognizer('hi;', mockRouteHandler))
|
||||||
|
.toThrowError(`Path "hi;" contains ";" which is not allowed in a route config.`);
|
||||||
|
expect(() => new PathRecognizer('hi=', mockRouteHandler))
|
||||||
|
.toThrowError(`Path "hi=" contains "=" which is not allowed in a route config.`);
|
||||||
|
expect(() => new PathRecognizer('hi(', mockRouteHandler))
|
||||||
|
.toThrowError(`Path "hi(" contains "(" which is not allowed in a route config.`);
|
||||||
|
expect(() => new PathRecognizer('hi)', mockRouteHandler))
|
||||||
|
.toThrowError(`Path "hi)" contains ")" which is not allowed in a route config.`);
|
||||||
|
expect(() => new PathRecognizer('hi//there', mockRouteHandler))
|
||||||
|
.toThrowError(`Path "hi//there" contains "//" which is not allowed in a route config.`);
|
||||||
|
});
|
||||||
|
|
||||||
describe('matrix params', () => {
|
describe('matrix params', () => {
|
||||||
it('should recognize a trailing matrix value on a path value and assign it to the params return value',
|
it('should recognize a trailing matrix value on a path value and assign it to the params return value',
|
||||||
() => {
|
() => {
|
||||||
|
|
Loading…
Reference in New Issue