Throw error for invalid extension names#9538
Conversation
Summary of ChangesHello @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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| 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.`, | ||
| ); | ||
| } |
There was a problem hiding this comment.
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.
| 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.`, | |
| ); | |
| } |
|
Size Change: +514 B (0%) Total Size: 17.4 MB ℹ️ View Unchanged
|
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
Linked issues / bugs