fix(router): use encodeUri/decodeUri to encode fragment
This commit is contained in:
parent
0bb516fae2
commit
bb9dfbc578
|
@ -182,9 +182,8 @@ export class DefaultUrlSerializer implements UrlSerializer {
|
||||||
serialize(tree: UrlTree): string {
|
serialize(tree: UrlTree): string {
|
||||||
const segment = `/${serializeSegment(tree.root, true)}`;
|
const segment = `/${serializeSegment(tree.root, true)}`;
|
||||||
const query = serializeQueryParams(tree.queryParams);
|
const query = serializeQueryParams(tree.queryParams);
|
||||||
const fragment = tree.fragment !== null && tree.fragment !== undefined ?
|
const fragment =
|
||||||
`#${encodeURIComponent(tree.fragment)}` :
|
tree.fragment !== null && tree.fragment !== undefined ? `#${encodeURI(tree.fragment)}` : '';
|
||||||
'';
|
|
||||||
return `${segment}${query}${fragment}`;
|
return `${segment}${query}${fragment}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -371,7 +370,7 @@ class UrlParser {
|
||||||
|
|
||||||
parseFragment(): string {
|
parseFragment(): string {
|
||||||
if (this.peekStartsWith('#')) {
|
if (this.peekStartsWith('#')) {
|
||||||
return decode(this.remaining.substring(1));
|
return decodeURI(this.remaining.substring(1));
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,10 +207,10 @@ describe('url serializer', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should encode/decode fragment', () => {
|
it('should encode/decode fragment', () => {
|
||||||
const u = `/one#${encode("one two")}`;
|
const u = `/one#${encodeURI("one two=three four")}`;
|
||||||
const tree = url.parse(u);
|
const tree = url.parse(u);
|
||||||
|
|
||||||
expect(tree.fragment).toEqual('one two');
|
expect(tree.fragment).toEqual('one two=three four');
|
||||||
expect(url.serialize(tree)).toEqual(u);
|
expect(url.serialize(tree)).toEqual(u);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue