Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
<fix>(resource_url_resolver): Makes resolved URLs absolute
Browse files Browse the repository at this point in the history
Makes resolved type URLs absolute instead of relative. When they are relative
it is difficult to reuse components. Using pub serve relative URLs are resolved
because pub does some magic to allow add symlinks to the packages directory
where needed. In production relative URLs make it difficult to add file handlers
to the locations that are needed, as the location will be determined based on
the current browser path or route. It also makes the template cache harder to
populate because the same resource may need to be served from two separate
URLs.

Closes #1599
  • Loading branch information
Ted Sander authored and rkirov committed Jan 28, 2015
1 parent 0961b6e commit 0b5df6b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
8 changes: 3 additions & 5 deletions lib/core_dom/resource_url_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,11 @@ class ResourceUrlResolver {
// If it's not absolute, then resolve it first
Uri resolved = baseUri.resolve(uri);

// If it's package-relative, tack on 'packages/' - Note that eventually
// we may want to change this to be '/packages/' to make it truly absolute
// If it's package-relative, tack on '/packages/'
if (resolved.scheme == 'package') {
return 'packages/${resolved.path}';
return '/packages/${resolved.path}';
} else if (resolved.isAbsolute && resolved.toString().startsWith(_baseUri)) {
var path = resolved.path;
return path.startsWith("/") ? path.substring(1) : path;
return resolved.path;
} else {
return resolved.toString();
}
Expand Down
2 changes: 1 addition & 1 deletion test/_specs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ e(String html) => es(html).first;
// this file, _specs.dart, is at path /base/test/_specs.dart. However, if
// you're using a different test server or reconfigured the base prefix, then
// you can set this to something different.
String TEST_SERVER_BASE_PREFIX = "base/";
String TEST_SERVER_BASE_PREFIX = "/base/";

Expect expect(actual, [matcher]) {
final expect = new Expect(actual);
Expand Down
20 changes: 10 additions & 10 deletions test/core_dom/resource_url_resolver_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,18 @@ _run_resolver({useRelativeUrls}) {

testBothSchemes(
urlToResolve: 'package:a.b/c/d/foo2.html',
expectedForPackageScheme: 'packages/a.b/c/d/foo2.html',
expectedForHttpScheme: 'packages/a.b/c/d/foo2.html');
expectedForPackageScheme: '/packages/a.b/c/d/foo2.html',
expectedForHttpScheme: '/packages/a.b/c/d/foo2.html');

testBothSchemes(
urlToResolve: 'image.png',
expectedForPackageScheme: 'packages/angular/test/core_dom/image.png',
expectedForHttpScheme: 'a/b/image.png');
expectedForPackageScheme: '/packages/angular/test/core_dom/image.png',
expectedForHttpScheme: '/a/b/image.png');

testBothSchemes(
urlToResolve: './image2.png',
expectedForPackageScheme: 'packages/angular/test/core_dom/image2.png',
expectedForHttpScheme: 'a/b/image2.png');
expectedForPackageScheme: '/packages/angular/test/core_dom/image2.png',
expectedForHttpScheme: '/a/b/image2.png');

testBothSchemes(
urlToResolve: '/image3.png',
Expand All @@ -225,13 +225,13 @@ _run_resolver({useRelativeUrls}) {

testBothSchemes(
urlToResolve: 'HTTP://LOCALHOST/a/b/image4.png',
expectedForPackageScheme: 'a/b/image4.png',
expectedForHttpScheme: 'a/b/image4.png');
expectedForPackageScheme: '/a/b/image4.png',
expectedForHttpScheme: '/a/b/image4.png');

testBothSchemes(
urlToResolve: 'HTTP://LOCALHOST/packages/angular/test/core_dom/foo3.html',
expectedForPackageScheme: 'packages/angular/test/core_dom/foo3.html',
expectedForHttpScheme: 'packages/angular/test/core_dom/foo3.html');
expectedForPackageScheme: '/packages/angular/test/core_dom/foo3.html',
expectedForHttpScheme: '/packages/angular/test/core_dom/foo3.html');

});
}
Expand Down

0 comments on commit 0b5df6b

Please sign in to comment.