Skip to content

Commit

Permalink
fix(router): use encodeUri/decodeUri to encode fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
vsavkin authored and vicb committed Aug 26, 2016
1 parent 0bb516f commit bb9dfbc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
7 changes: 3 additions & 4 deletions modules/@angular/router/src/url_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ 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 !== undefined ?
`#${encodeURIComponent(tree.fragment)}` :
'';
const fragment =
tree.fragment !== null && tree.fragment !== undefined ? `#${encodeURI(tree.fragment)}` : '';
return `${segment}${query}${fragment}`;
}
}
Expand Down Expand Up @@ -371,7 +370,7 @@ class UrlParser {

parseFragment(): string {
if (this.peekStartsWith('#')) {
return decode(this.remaining.substring(1));
return decodeURI(this.remaining.substring(1));
} else {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/@angular/router/test/url_serializer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ describe('url serializer', () => {
});

it('should encode/decode fragment', () => {
const u = `/one#${encode("one two")}`;
const u = `/one#${encodeURI("one two=three four")}`;
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);
});
});
Expand Down

0 comments on commit bb9dfbc

Please sign in to comment.