Skip to content

Commit

Permalink
fix(url_resolver): always replace package: in Dart, even if it came…
Browse files Browse the repository at this point in the history
… from `baseUrl`.

Closes #4775
  • Loading branch information
tbosch committed Oct 15, 2015
1 parent 5256457 commit fd9b675
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
19 changes: 12 additions & 7 deletions modules/angular2/src/core/compiler/url_resolver.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -28,14 +32,15 @@ class UrlResolver {
*/
String resolve(String baseUrl, String url) {
Uri uri = Uri.parse(url);
if (!uri.isAbsolute) {
Uri baseUri = Uri.parse(baseUrl);
uri = baseUri.resolveUri(uri);
}

if (uri.scheme == 'package') {
if (_packagePrefix != null && uri.scheme == 'package') {
return '$_packagePrefix/${uri.path}';
} else {
return uri.toString();
}

if (uri.isAbsolute) return uri.toString();

Uri baseUri = Uri.parse(baseUrl);
return baseUri.resolveUri(uri).toString();
}
}
5 changes: 5 additions & 0 deletions modules/angular2/src/core/compiler/url_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
4 changes: 3 additions & 1 deletion modules/angular2/test/core/compiler/test_bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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})
];

0 comments on commit fd9b675

Please sign in to comment.