From fd9b67537d4651eae06e8bfa21175979467c6fe5 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 15 Oct 2015 16:03:23 -0700 Subject: [PATCH] fix(url_resolver): always replace `package:` in Dart, even if it came from `baseUrl`. Closes #4775 --- .../src/core/compiler/url_resolver.dart | 21 ++++++++++++------- .../src/core/compiler/url_resolver.ts | 5 +++++ .../test/core/compiler/test_bindings.ts | 4 +++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/modules/angular2/src/core/compiler/url_resolver.dart b/modules/angular2/src/core/compiler/url_resolver.dart index 8d38a9bdf8..2f9b4a4562 100644 --- a/modules/angular2/src/core/compiler/url_resolver.dart +++ b/modules/angular2/src/core/compiler/url_resolver.dart @@ -1,6 +1,10 @@ library angular2.src.services.url_resolver; -import 'package:angular2/src/core/di.dart' show Injectable; +import 'package:angular2/src/core/di.dart' show Injectable, Provider; + +UrlResolver createWithoutPackagePrefix() { + return new UrlResolver.withUrlPrefix(null); +} @Injectable() class UrlResolver { @@ -28,14 +32,15 @@ class UrlResolver { */ String resolve(String baseUrl, String url) { Uri uri = Uri.parse(url); - - if (uri.scheme == 'package') { - return '$_packagePrefix/${uri.path}'; + if (!uri.isAbsolute) { + Uri baseUri = Uri.parse(baseUrl); + uri = baseUri.resolveUri(uri); } - if (uri.isAbsolute) return uri.toString(); - - Uri baseUri = Uri.parse(baseUrl); - return baseUri.resolveUri(uri).toString(); + if (_packagePrefix != null && uri.scheme == 'package') { + return '$_packagePrefix/${uri.path}'; + } else { + return uri.toString(); + } } } diff --git a/modules/angular2/src/core/compiler/url_resolver.ts b/modules/angular2/src/core/compiler/url_resolver.ts index b8e70be928..6609faba6c 100644 --- a/modules/angular2/src/core/compiler/url_resolver.ts +++ b/modules/angular2/src/core/compiler/url_resolver.ts @@ -3,6 +3,11 @@ import {isPresent, isBlank, RegExpWrapper, normalizeBlank} from 'angular2/src/co import {BaseException, WrappedException} from 'angular2/src/core/facade/exceptions'; import {ListWrapper} from 'angular2/src/core/facade/collection'; +export function createWithoutPackagePrefix(): UrlResolver { + return new UrlResolver(); +} + + /** * Used by the {@link Compiler} when resolving HTML and CSS template URLs. * diff --git a/modules/angular2/test/core/compiler/test_bindings.ts b/modules/angular2/test/core/compiler/test_bindings.ts index 2819ef3da5..64db80d7d8 100644 --- a/modules/angular2/test/core/compiler/test_bindings.ts +++ b/modules/angular2/test/core/compiler/test_bindings.ts @@ -3,8 +3,10 @@ import {MockSchemaRegistry} from './schema_registry_mock'; import {ElementSchemaRegistry} from 'angular2/src/core/compiler/schema/element_schema_registry'; import {MockXHR} from 'angular2/src/core/compiler/xhr_mock'; import {XHR} from 'angular2/src/core/compiler/xhr'; +import {UrlResolver, createWithoutPackagePrefix} from 'angular2/src/core/compiler/url_resolver'; export var TEST_PROVIDERS = [ provide(ElementSchemaRegistry, {useValue: new MockSchemaRegistry({}, {})}), - provide(XHR, {useClass: MockXHR}) + provide(XHR, {useClass: MockXHR}), + provide(UrlResolver, {useFactory: createWithoutPackagePrefix}) ];