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

Unified Diff: utils/pub/pubspec.dart

Issue 11412017: Validate that the homepage is using an approved scheme. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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 | « no previous file | 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 8218266bbd093d9a5bac9aafaae887d1ecd360ee..20f15a1d989b6953ed35bbcc0b16eeea5c7db9ef 100644
--- a/utils/pub/pubspec.dart
+++ b/utils/pub/pubspec.dart
@@ -76,12 +76,28 @@ 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:
+ // TODO(rnystrom): We should split this validation into separate layers:
+ // 1. Stuff that is required in any pubspec to perform any command. Things
+ // like "must have a name". That should go here.
+ // 2. Stuff that is required to upload a package. Things like "homepage
+ // must use a valid scheme". That should go elsewhere. pub upload should
+ // call it, and we should provide a separate command to show the user,
+ // and also expose it to the editor in some way.
+
+ if (parsedPubspec.containsKey('homepage')) {
+ var homepage = parsedPubspec['homepage'];
+
+ if (homepage is! String) {
+ throw new FormatException(
+ 'The "homepage" field should be a string, but was "$homepage".');
+ }
- if (parsedPubspec.containsKey('homepage') &&
- parsedPubspec['homepage'] is! String) {
- throw new FormatException(
- 'The "homepage" field should be a string, but was '
- '${parsedPubspec["homepage"]}.');
+ var goodScheme = new RegExp(r'^https?:');
+ if (!goodScheme.hasMatch(homepage)) {
+ throw new FormatException(
+ 'The "homepage" field should be an "http:" or "https:" URL, but '
+ 'was "$homepage".');
+ }
}
if (parsedPubspec.containsKey('author') &&
« no previous file with comments | « no previous file | utils/tests/pub/pubspec_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698