Skip to content

Make sure that extensions are bundled with the package they claim to be. - #9981

Open
johnpryan wants to merge 1 commit into
flutter:masterfrom
johnpryan:package-centric-extensions
Open

Make sure that extensions are bundled with the package they claim to be.#9981
johnpryan wants to merge 1 commit into
flutter:masterfrom
johnpryan:package-centric-extensions

Conversation

@johnpryan

Copy link
Copy Markdown
Contributor

With this change, extensions are enabled if and only if the package name on disk matches the package name in extension/devtools/config.yaml.

This supersedes #9965

With this change, extensions are enabled if and only if the package name
on disk matches the package name in extension/devtools/config.yaml.
@johnpryan
johnpryan requested review from a team, bkonyi and kenzieschmoll as code owners August 26, 2026 21:40
@johnpryan
johnpryan requested review from srawlins and removed request for a team August 26, 2026 21:40

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves DevTools extension isolation by tracking the providing package name for enablement, deduplication, and asset loading, and adds validation checks for extension names. The review feedback highlights a compilation error in _extensions_api.dart due to invalid map literal syntax, a potential runtime TypeError in _validate.dart when casting the configuration name, and a suggestion to normalize packageRoot in extension_manager.dart for more robust path comparisons.

Comment on lines +96 to +97
ExtensionsApi.extensionPackagePropertyName: ?extensionPackage,
ExtensionsApi.enabledStatePropertyName: ?enable?.toString(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

[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.

        if (extensionPackage != null)
          ExtensionsApi.extensionPackagePropertyName: extensionPackage,
        if (enable != null)
          ExtensionsApi.enabledStatePropertyName: enable.toString(),
References
  1. Prefix every comment with a severity: [MUST-FIX] for logical bugs, [CONCERN] for maintainability issues. (link)

Comment on lines +123 to +125
final configName = configYaml['name'] as String?;
final underscoresAndLetters = RegExp(r'^[a-z0-9_]*$');
if (configName == null || !underscoresAndLetters.hasMatch(configName)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

[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
final configName = configYaml['name'] as String?;
final underscoresAndLetters = RegExp(r'^[a-z0-9_]*$');
if (configName == null || !underscoresAndLetters.hasMatch(configName)) {
final configName = configYaml['name'];
final underscoresAndLetters = RegExp(r'^[a-z0-9_]*$');
if (configName is! String || !underscoresAndLetters.hasMatch(configName)) {
References
  1. Prefix every comment with a severity: [MUST-FIX] for logical bugs, [CONCERN] for maintainability issues. (link)

'extension',
'devtools',
relativeExtensionLocation,
final packageRoot = extension.rootUri.toFilePath();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

[CONCERN] To ensure that path comparisons using 'path.isWithin' are robust and behave consistently across different platforms and environments, it is safer to normalize 'packageRoot' as well.

Suggested change
final packageRoot = extension.rootUri.toFilePath();
final packageRoot = path.normalize(extension.rootUri.toFilePath());
References
  1. Prefix every comment with a severity: [MUST-FIX] for logical bugs, [CONCERN] for maintainability issues. (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant