-
Notifications
You must be signed in to change notification settings - Fork 401
Make sure that extensions are bundled with the package they claim to be. #9981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -78,6 +78,14 @@ void _validateDirectoryContents(String packagePath) { | |||||||||||||
| throw FileSystemException('${packageDirectory.path} directory not found'); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| final pubspecFile = File(path.join(packageDirectory.path, 'pubspec.yaml')); | ||||||||||||||
| if (!pubspecFile.existsSync()) { | ||||||||||||||
| throw const FileSystemException(''' | ||||||||||||||
| A pubspec.yaml file is required, but none was found. | ||||||||||||||
| See ${ValidateExtensionCommand.docUrl}. | ||||||||||||||
| '''); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| final devtoolsExtensionDir = Directory( | ||||||||||||||
| path.join(packageDirectory.path, 'extension', 'devtools'), | ||||||||||||||
| ); | ||||||||||||||
|
|
@@ -109,6 +117,17 @@ An extension/devtools/config.yaml file is required, but none was found. | |||||||||||||
| See ${ValidateExtensionCommand.docUrl}. | ||||||||||||||
| '''); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Ensure the extension's name is a valid identifier. | ||||||||||||||
| final configYaml = _configAsMap(packagePath); | ||||||||||||||
| final configName = configYaml['name'] as String?; | ||||||||||||||
| final underscoresAndLetters = RegExp(r'^[a-z0-9_]*$'); | ||||||||||||||
| if (configName == null || !underscoresAndLetters.hasMatch(configName)) { | ||||||||||||||
|
Comment on lines
+123
to
+125
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [CONCERN] Casting configYaml['name'] directly to String? using 'as String?' will throw a TypeError at runtime if the value in config.yaml is of another type (e.g., an integer or boolean). It is safer to perform a type check ('is! String') to throw a descriptive StateError instead.
Suggested change
References
|
||||||||||||||
| throw StateError( | ||||||||||||||
| 'The "name" field in config.yaml should only contain lowercase letters, ' | ||||||||||||||
| 'numbers, and underscores but instead was "$configName".', | ||||||||||||||
| ); | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| Map<String, Object?> _configAsMap(String packagePath) { | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[MUST-FIX] The syntax '?expression' is invalid in Dart map literals and will cause a compilation error. Use conditional elements ('if (condition)') to conditionally include these query parameters, matching the pattern used previously.
References