From 4f5e40567658ff69e728273093a4b3e679865f4e Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Sat, 8 Aug 2015 09:25:24 +0200 Subject: [PATCH] fix(UrlResolver): encode URLs before resolving This commits makes JS implementation to behave like Dart one. Fixes #3543 Closes #3545 --- modules/angular2/src/services/url_resolver.ts | 2 +- modules/angular2/test/services/url_resolver_spec.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/services/url_resolver.ts b/modules/angular2/src/services/url_resolver.ts index aa515e9f56..924c9f88d8 100644 --- a/modules/angular2/src/services/url_resolver.ts +++ b/modules/angular2/src/services/url_resolver.ts @@ -272,7 +272,7 @@ function _joinAndCanonicalizePath(parts: List): string { * @return {string} */ function _resolveUrl(base: string, url: string): string { - var parts = _split(url); + var parts = _split(encodeURI(url)); var baseParts = _split(base); if (isPresent(parts[_ComponentIndex.SCHEME])) { diff --git a/modules/angular2/test/services/url_resolver_spec.ts b/modules/angular2/test/services/url_resolver_spec.ts index 830205a694..385cb3bec2 100644 --- a/modules/angular2/test/services/url_resolver_spec.ts +++ b/modules/angular2/test/services/url_resolver_spec.ts @@ -70,5 +70,13 @@ export function main() { expect(resolver.resolve('foo/baz/', '/bar')).toEqual('/bar'); }); }); + + describe('corner and error cases', () => { + it('should encode URLs before resolving', () => { + expect(resolver.resolve('foo/baz', `

Hello +

`)) + .toEqual('foo/%3Cp%20#p%3EHello%0A%20%20%20%20%20%20%20%20%3C/p%3E'); + }); + }); }); }