Skip to content

Throw error for invalid extension names#9538

Merged
chrstnb merged 3 commits into
mainfrom
cb/fixwrongnames
Sep 25, 2025
Merged

Throw error for invalid extension names#9538
chrstnb merged 3 commits into
mainfrom
cb/fixwrongnames

Conversation

@chrstnb

@chrstnb chrstnb commented Sep 25, 2025

Copy link
Copy Markdown
Contributor

TLDR

Throw an error if the extension name is not valid, where valid is defined as a-z, A-Z, dashes, and numbers.

Dive Deeper

Reviewer Test Plan

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

@chrstnb chrstnb requested a review from a team as a code owner September 25, 2025 03:14
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @chrstnb, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the robustness of the extension loading mechanism by introducing explicit validation for extension names. It ensures that all extension names conform to a consistent format, preventing potential issues caused by malformed names and providing immediate feedback to users when an invalid name is encountered.

Highlights

  • Extension Name Validation: Implemented a new validateName function to enforce strict naming conventions for extensions, allowing only lowercase letters, numbers, and dashes.
  • Error Handling: The loadExtensionConfig function now utilizes validateName to throw an error if an invalid extension name is detected during configuration loading.
  • Documentation Update: The docs/extension.md file has been updated to reflect the refined naming convention, explicitly stating that numbers are also allowed in extension names.
  • Test Coverage: A new test case has been added to extension.test.ts to ensure that the system correctly identifies and rejects invalid extension names, verifying the new validation logic.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@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 introduces validation for extension names to ensure they adhere to a specific format, which is a great improvement for robustness. The changes include adding a validateName function, integrating it into the extension loading process, and adding a corresponding test case. My main feedback is regarding an inconsistency between the implementation and the documentation for name validation. The documentation specifies lowercase names, but the implementation allows uppercase letters. I've suggested a change to align the implementation with the documented standard.

Comment on lines +553 to +557
if (!/^[a-zA-Z0-9-]+$/.test(name)) {
throw new Error(
`Invalid extension name: "${name}". Only letters (a-z, A-Z), numbers (0-9), and dashes (-) are allowed.`,
);
}

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.

high

The documentation in docs/extension.md (both before and after this PR's changes) specifies that extension names should be lowercase. However, the regular expression /^[a-zA-Z0-9-]+$/ allows uppercase letters. This inconsistency can lead to confusion and potential issues, especially since other parts of the codebase (like annotateActiveExtensions and uninstallExtension) perform case-insensitive comparisons on extension names.

To maintain consistency and prevent potential bugs, it's best to enforce the lowercase constraint as specified in the documentation.

Suggested change
if (!/^[a-zA-Z0-9-]+$/.test(name)) {
throw new Error(
`Invalid extension name: "${name}". Only letters (a-z, A-Z), numbers (0-9), and dashes (-) are allowed.`,
);
}
if (!/^[a-z0-9-]+$/.test(name)) {
throw new Error(
`Invalid extension name: "${name}". Only lowercase letters (a-z), numbers (0-9), and dashes (-) are allowed.`,
);
}

@github-actions

github-actions Bot commented Sep 25, 2025

Copy link
Copy Markdown

Size Change: +514 B (0%)

Total Size: 17.4 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 17.4 MB +514 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 830 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

@chrstnb chrstnb added this pull request to the merge queue Sep 25, 2025
Merged via the queue into main with commit 2d76cdf Sep 25, 2025
16 of 19 checks passed
@chrstnb chrstnb deleted the cb/fixwrongnames branch September 25, 2025 18:16
geoffdowns pushed a commit to geoffdowns/gemini-cli that referenced this pull request Sep 26, 2025
giraffe-tree pushed a commit to giraffe-tree/gemini-cli that referenced this pull request Oct 10, 2025
@sripasg sripasg added the size/s A small PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants