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

Side by Side 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. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | lib/src/utils.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library pub.pubspec; 5 library pub.pubspec;
6 6
7 import 'package:path/path.dart' as path; 7 import 'package:path/path.dart' as path;
8 import 'package:pub_semver/pub_semver.dart'; 8 import 'package:pub_semver/pub_semver.dart';
9 import 'package:source_span/source_span.dart'; 9 import 'package:source_span/source_span.dart';
10 import 'package:yaml/yaml.dart'; 10 import 'package:yaml/yaml.dart';
11 11
12 import 'barback/transformer_config.dart'; 12 import 'barback/transformer_config.dart';
13 import 'exceptions.dart'; 13 import 'exceptions.dart';
14 import 'io.dart'; 14 import 'io.dart';
15 import 'package.dart'; 15 import 'package.dart';
16 import 'source_registry.dart'; 16 import 'source_registry.dart';
17 import 'utils.dart'; 17 import 'utils.dart';
18 18
19 /// A regular expression matching allowed package names.
20 ///
21 /// This allows dot-separated valid Dart identifiers. The dots are there for
22 /// compatibility with Google's internal Dart packages, but they may not be used
23 /// when publishing a package to pub.dartlang.org.
24 final _packageName = new RegExp(
25 "^${identifierRegExp.pattern}(\\.${identifierRegExp.pattern})*\$");
26
19 /// The parsed contents of a pubspec file. 27 /// The parsed contents of a pubspec file.
20 /// 28 ///
21 /// The fields of a pubspec are, for the most part, validated when they're first 29 /// The fields of a pubspec are, for the most part, validated when they're first
22 /// accessed. This allows a partially-invalid pubspec to be used if only the 30 /// accessed. This allows a partially-invalid pubspec to be used if only the
23 /// valid portions are relevant. To get a list of all errors in the pubspec, use 31 /// valid portions are relevant. To get a list of all errors in the pubspec, use
24 /// [allErrors]. 32 /// [allErrors].
25 class Pubspec { 33 class Pubspec {
26 // If a new lazily-initialized field is added to this class and the 34 // If a new lazily-initialized field is added to this class and the
27 // initialization can throw a [PubspecException], that error should also be 35 // initialization can throw a [PubspecException], that error should also be
28 // exposed through [allErrors]. 36 // exposed through [allErrors].
(...skipping 20 matching lines...) Expand all
49 String get name { 57 String get name {
50 if (_name != null) return _name; 58 if (_name != null) return _name;
51 59
52 var name = fields['name']; 60 var name = fields['name'];
53 if (name == null) { 61 if (name == null) {
54 throw new PubspecException( 62 throw new PubspecException(
55 'Missing the required "name" field.', fields.span); 63 'Missing the required "name" field.', fields.span);
56 } else if (name is! String) { 64 } else if (name is! String) {
57 throw new PubspecException( 65 throw new PubspecException(
58 '"name" field must be a string.', fields.nodes['name'].span); 66 '"name" field must be a string.', fields.nodes['name'].span);
67 } else if (!_packageName.hasMatch(name)) {
68 throw new PubspecException(
69 '"name" field must be a valid Dart identifier.',
70 fields.nodes['name'].span);
71 } else if (reservedWords.contains(name)) {
72 throw new PubspecException(
73 '"name" field may not be a Dart reserved word.',
74 fields.nodes['name'].span);
59 } 75 }
60 76
61 _name = name; 77 _name = name;
62 return _name; 78 return _name;
63 } 79 }
64 String _name; 80 String _name;
65 81
66 /// The package's version. 82 /// The package's version.
67 Version get version { 83 Version get version {
68 if (_version != null) return _version; 84 if (_version != null) return _version;
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 implements ApplicationException { 595 implements ApplicationException {
580 PubspecException(String message, SourceSpan span) 596 PubspecException(String message, SourceSpan span)
581 : super(message, span); 597 : super(message, span);
582 } 598 }
583 599
584 /// Returns whether [uri] is a file URI. 600 /// Returns whether [uri] is a file URI.
585 /// 601 ///
586 /// This is slightly more complicated than just checking if the scheme is 602 /// This is slightly more complicated than just checking if the scheme is
587 /// 'file', since relative URIs also refer to the filesystem on the VM. 603 /// 'file', since relative URIs also refer to the filesystem on the VM.
588 bool _isFileUri(Uri uri) => uri.scheme == 'file' || uri.scheme == ''; 604 bool _isFileUri(Uri uri) => uri.scheme == 'file' || uri.scheme == '';
OLDNEW
« no previous file with comments | « no previous file | lib/src/utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698