fix(router): encode/decode params and path segments
This commit is contained in:
@ -183,7 +183,7 @@ export class DefaultUrlSerializer implements UrlSerializer {
|
||||
serialize(tree: UrlTree): string {
|
||||
const segment = `/${serializeSegment(tree.root, true)}`;
|
||||
const query = serializeQueryParams(tree.queryParams);
|
||||
const fragment = tree.fragment !== null ? `#${tree.fragment}` : '';
|
||||
const fragment = tree.fragment !== null ? `#${encodeURIComponent(tree.fragment)}` : '';
|
||||
return `${segment}${query}${fragment}`;
|
||||
}
|
||||
}
|
||||
@ -223,15 +223,18 @@ function serializeSegment(segment: UrlSegment, root: boolean): string {
|
||||
}
|
||||
|
||||
export function serializePath(path: UrlPathWithParams): string {
|
||||
return `${path.path}${serializeParams(path.parameters)}`;
|
||||
return `${encodeURIComponent(path.path)}${serializeParams(path.parameters)}`;
|
||||
}
|
||||
|
||||
function serializeParams(params: {[key: string]: string}): string {
|
||||
return pairs(params).map(p => `;${p.first}=${p.second}`).join('');
|
||||
return pairs(params)
|
||||
.map(p => `;${encodeURIComponent(p.first)}=${encodeURIComponent(p.second)}`)
|
||||
.join('');
|
||||
}
|
||||
|
||||
function serializeQueryParams(params: {[key: string]: string}): string {
|
||||
const strs = pairs(params).map(p => `${p.first}=${p.second}`);
|
||||
const strs =
|
||||
pairs(params).map(p => `${encodeURIComponent(p.first)}=${encodeURIComponent(p.second)}`);
|
||||
return strs.length > 0 ? `?${strs.join("&")}` : '';
|
||||
}
|
||||
|
||||
@ -335,7 +338,7 @@ class UrlParser {
|
||||
if (this.peekStartsWith(';')) {
|
||||
matrixParams = this.parseMatrixParams();
|
||||
}
|
||||
return new UrlPathWithParams(path, matrixParams);
|
||||
return new UrlPathWithParams(decodeURIComponent(path), matrixParams);
|
||||
}
|
||||
|
||||
parseQueryParams(): {[key: string]: any} {
|
||||
@ -353,7 +356,7 @@ class UrlParser {
|
||||
|
||||
parseFragment(): string {
|
||||
if (this.peekStartsWith('#')) {
|
||||
return this.remaining.substring(1);
|
||||
return decodeURIComponent(this.remaining.substring(1));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
@ -384,7 +387,7 @@ class UrlParser {
|
||||
}
|
||||
}
|
||||
|
||||
params[key] = value;
|
||||
params[decodeURIComponent(key)] = decodeURIComponent(value);
|
||||
}
|
||||
|
||||
parseQueryParam(params: {[key: string]: any}): void {
|
||||
@ -402,7 +405,7 @@ class UrlParser {
|
||||
this.capture(value);
|
||||
}
|
||||
}
|
||||
params[key] = value;
|
||||
params[decodeURIComponent(key)] = decodeURIComponent(value);
|
||||
}
|
||||
|
||||
parseParens(allowPrimary: boolean): {[key: string]: UrlSegment} {
|
||||
|
Reference in New Issue
Block a user