fix(url_resolver): always replace `package:` in Dart, even if it came from `baseUrl`.

Closes #4775
This commit is contained in:
Tobias Bosch 2015-10-15 16:03:23 -07:00
parent 5256457144
commit fd9b67537d
3 changed files with 21 additions and 9 deletions

View File

@ -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) return uri.toString();
if (!uri.isAbsolute) {
Uri baseUri = Uri.parse(baseUrl);
return baseUri.resolveUri(uri).toString();
uri = baseUri.resolveUri(uri);
}
if (_packagePrefix != null && uri.scheme == 'package') {
return '$_packagePrefix/${uri.path}';
} else {
return uri.toString();
}
}
}

View File

@ -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.
*

View File

@ -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})
];