Chromium Code Reviews

Unified Diff: lib/src/pubspec.dart

Issue 1493463002: Disallow invalid package names in Pubspec. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Code review changes Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « no previous file | lib/src/utils.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/pubspec.dart
diff --git a/lib/src/pubspec.dart b/lib/src/pubspec.dart
index 28b1375cbf9e07ad52445b89d8e7c9c9f300db1a..e53a252b2fc700c710a1100830b80eed40226ffb 100644
--- a/lib/src/pubspec.dart
+++ b/lib/src/pubspec.dart
@@ -16,6 +16,14 @@ import 'package.dart';
import 'source_registry.dart';
import 'utils.dart';
+/// A regular expression matching allowed package names.
+///
+/// This allows dot-separated valid Dart identifiers. The dots are there for
+/// compatibility with Google's internal Dart packages, but they may not be used
+/// when publishing a package to pub.dartlang.org.
+final _packageName = new RegExp(
+ "^${identifierRegExp.pattern}(\\.${identifierRegExp.pattern})*\$");
+
/// The parsed contents of a pubspec file.
///
/// The fields of a pubspec are, for the most part, validated when they're first
@@ -56,6 +64,14 @@ class Pubspec {
} else if (name is! String) {
throw new PubspecException(
'"name" field must be a string.', fields.nodes['name'].span);
+ } else if (!_packageName.hasMatch(name)) {
+ throw new PubspecException(
+ '"name" field must be a valid Dart identifier.',
+ fields.nodes['name'].span);
+ } else if (reservedWords.contains(name)) {
+ throw new PubspecException(
+ '"name" field may not be a Dart reserved word.',
+ fields.nodes['name'].span);
}
_name = name;
« no previous file with comments | « no previous file | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine