Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Unified Diff: utils/pub/pubspec.dart

Issue 11235067: Apply patch from other client. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/package.dart ('k') | utils/tests/pub/pubspec_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/pubspec.dart
diff --git a/utils/pub/pubspec.dart b/utils/pub/pubspec.dart
index 6fbe647e525f9edcbc33eca0507f057a46a1ec68..ac037fadffa2e0c0d713f22d9d35e8b9e03c643b 100644
--- a/utils/pub/pubspec.dart
+++ b/utils/pub/pubspec.dart
@@ -59,7 +59,13 @@ class Pubspec {
throw new FormatException('The pubspec must be a YAML mapping.');
}
- if (parsedPubspec.containsKey('name')) name = parsedPubspec['name'];
+ if (parsedPubspec.containsKey('name')) {
+ name = parsedPubspec['name'];
+ if (name is! String) {
+ throw new FormatException(
+ 'The pubspec "name" field should be a string, but was "$name".');
+ }
+ }
if (parsedPubspec.containsKey('version')) {
version = new Version.parse(parsedPubspec['version']);
@@ -70,7 +76,8 @@ class Pubspec {
if (dependencyEntries is! Map ||
dependencyEntries.getKeys().some((e) => e is! String)) {
throw new FormatException(
- 'The pubspec dependencies must be a map of package names.');
+ 'The pubspec dependencies should be a map of package names, but '
+ 'was ${dependencyEntries}.');
}
dependencyEntries.forEach((name, spec) {
@@ -98,14 +105,15 @@ class Pubspec {
var sourceName = only(sourceNames);
if (sourceName is! String) {
throw new FormatException(
- 'Source name $sourceName must be a string.');
+ 'Source name $sourceName should be a string.');
}
source = sources[sourceName];
description = spec[sourceName];
} else {
throw new FormatException(
- 'Dependency specification $spec must be a string or a mapping.');
+ 'Dependency specification $spec should be a string or a '
+ 'mapping.');
}
source.validateDescription(description, fromLockFile: false);
@@ -115,6 +123,43 @@ class Pubspec {
});
}
+ // Even though the pub app itself doesn't use these fields, we validate
+ // them here so that users find errors early before they try to upload to
+ // the server:
+
+ if (parsedPubspec.containsKey('homepage') &&
+ parsedPubspec['homepage'] is! String) {
+ throw new FormatException(
+ 'The "homepage" field should be a string, but was '
+ '${parsedPubspec["homepage"]}.');
+ }
+
+ if (parsedPubspec.containsKey('author') &&
+ parsedPubspec['author'] is! String) {
+ throw new FormatException(
+ 'The "author" field should be a string, but was '
+ '${parsedPubspec["author"]}.');
+ }
+
+ if (parsedPubspec.containsKey('authors')) {
+ var authors = parsedPubspec['authors'];
+ if (authors is List) {
+ // All of the elements must be strings.
+ if (!authors.every((author) => author is String)) {
+ throw new FormatException('The "authors" field should be a string '
+ 'or a list of strings, but was "$authors".');
+ }
+ } else if (authors is! String) {
+ throw new FormatException('The pubspec "authors" field should be a '
+ 'string or a list of strings, but was "$authors".');
+ }
+
+ if (parsedPubspec.containsKey('author')) {
+ throw new FormatException('A pubspec should not have both an "author" '
+ 'and an "authors" field.');
+ }
+ }
+
return new Pubspec(name, version, dependencies);
}
}
« no previous file with comments | « utils/pub/package.dart ('k') | utils/tests/pub/pubspec_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698