From 1d5dedc6baf67a22af185de54097bd171cf3823c Mon Sep 17 00:00:00 2001 From: "Lasse R.H. Nielsen" Date: Thu, 20 Aug 2015 11:17:58 +0200 Subject: [PATCH] Add slash to package dir URI after resolving reference against base. 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. R=sgjesse@google.com Review URL: https://codereview.chromium.org//1297923004. --- lib/packages_file.dart | 2 +- test/parse_test.dart | 32 ++++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/packages_file.dart b/lib/packages_file.dart index 3f432aa..f30781d 100644 --- a/lib/packages_file.dart +++ b/lib/packages_file.dart @@ -57,11 +57,11 @@ Map parse(List 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); diff --git a/test/parse_test.dart b/test/parse_test.dart index 6f830a1..8ed5c2e 100644 --- a/test/parse_test.dart +++ b/test/parse_test.dart @@ -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( @@ -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;="