Skip to content

Commit ca0d52f

Browse files
authored
Throw an error if publish_to isn't an absolute URL (#1769)
Closes #1766
1 parent a13bf1d commit ca0d52f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/src/pubspec.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,12 @@ class Pubspec {
446446

447447
// It must be "none" or a valid URL.
448448
if (publishTo != "none") {
449-
_wrapFormatException(
450-
'"publish_to" field', span, () => Uri.parse(publishTo));
449+
_wrapFormatException('"publish_to" field', span, () {
450+
var url = Uri.parse(publishTo);
451+
if (url.scheme.isEmpty) {
452+
throw new FormatException("must be an absolute URL.");
453+
}
454+
});
451455
}
452456
}
453457

test/pubspec_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ publish_to: none
557557
expectPubspecException('publish_to: http://bad.url:not-port',
558558
(pubspec) => pubspec.publishTo);
559559
});
560+
561+
test("throws on non-absolute URLs", () {
562+
expectPubspecException(
563+
'publish_to: pub.dartlang.org', (pubspec) => pubspec.publishTo);
564+
});
560565
});
561566

562567
group("executables", () {

0 commit comments

Comments
 (0)