Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
Add slash to package dir URI after resolving reference against base.
Browse files Browse the repository at this point in the history
Used to add slash to reference before resolving it.
It only makes a difference for the empty URI reference which
never makes sense anyway - this just ensures the error is the same
as on the VM. It is, arguably, what the specification requires.

[email protected]

Review URL: https://codereview.chromium.org//1297923004.
  • Loading branch information
lrhn committed Aug 20, 2015
1 parent 1998ff7 commit 1d5dedc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/packages_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ Map<String, Uri> parse(List<int> source, Uri baseLocation) {
}
var packageUri = new String.fromCharCodes(source, separatorIndex + 1, end);
var packageLocation = Uri.parse(packageUri);
packageLocation = baseLocation.resolveUri(packageLocation);
if (!packageLocation.path.endsWith('/')) {
packageLocation =
packageLocation.replace(path: packageLocation.path + "/");
}
packageLocation = baseLocation.resolveUri(packageLocation);
if (result.containsKey(packageName)) {
throw new FormatException(
"Same package name occured twice.", source, start);
Expand Down
32 changes: 24 additions & 8 deletions test/parse_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,27 @@ main() {
equals(base.resolve("../test/").resolve("bar/baz.dart")));
});

test("single absolute", () {
test("single absolute authority", () {
var packages = doParse(singleAbsoluteSample, base);
expect(packages.packages.toList(), equals(["foo"]));
expect(packages.resolve(Uri.parse("package:foo/bar/baz.dart")),
equals(Uri.parse("http://example.com/some/where/bar/baz.dart")));
});

test("single empty path", () {
var packages = doParse(singleEmptyPathSample, base);
expect(packages.packages.toList(), equals(["foo"]));
expect(packages.resolve(Uri.parse("package:foo/bar/baz.dart")),
equals(base.replace(path: "${base.path}/bar/baz.dart")));
});

test("single absolute path", () {
var packages = doParse(singleAbsolutePathSample, base);
expect(packages.packages.toList(), equals(["foo"]));
expect(packages.resolve(Uri.parse("package:foo/bar/baz.dart")),
equals(base.replace(path: "/test/bar/baz.dart")));
});

test("multiple", () {
var packages = doParse(multiRelativeSample, base);
expect(
Expand Down Expand Up @@ -121,14 +135,16 @@ Packages doParse(String sample, Uri baseUri) {
}

// Valid samples.
var emptySample = "";
var commentOnlySample = "# comment only\n";
var emptyLinesSample = "\n\n\r\n";
var singleRelativeSample = "foo:../test/\n";
var singleRelativeSampleNoSlash = "foo:../test\n";
var emptySample = "";
var commentOnlySample = "# comment only\n";
var emptyLinesSample = "\n\n\r\n";
var singleRelativeSample = "foo:../test/\n";
var singleRelativeSampleNoSlash = "foo:../test\n";
var singleRelativeSampleNoNewline = "foo:../test/";
var singleAbsoluteSample = "foo:http://example.com/some/where/\n";
var multiRelativeSample = "foo:../test/\nbar:../test2/\n";
var singleAbsoluteSample = "foo:http://example.com/some/where/\n";
var singleEmptyPathSample = "foo:\n";
var singleAbsolutePathSample = "foo:/test/\n";
var multiRelativeSample = "foo:../test/\nbar:../test2/\n";
// All valid path segment characters in an URI.
var allValidChars =
r"!$&'()*+,-.0123456789;="
Expand Down

0 comments on commit 1d5dedc

Please sign in to comment.