fix bad fallback logic external editor logic#17166
Conversation
Summary of ChangesHello @scidomino, 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 resolves a critical bug in the external editor selection process, ensuring that the CLI correctly prioritizes user-defined environment variables ( 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 fixes a bug in the fallback logic for determining the external editor, specifically addressing an operator precedence issue that caused it to ignore the VISUAL and EDITOR environment variables. From a security perspective, no high or critical severity vulnerabilities were identified, and the changes do not introduce issues related to command injection, input sanitization, or access control. I've also provided a suggestion to improve robustness by handling cases where VISUAL or EDITOR are set to an empty or whitespace-only string, which could lead to application crashes.
| command = | ||
| (process.env['VISUAL'] ?? | ||
| process.env['VISUAL'] ?? | ||
| process.env['EDITOR'] ?? | ||
| process.platform === 'win32') | ||
| ? 'notepad' | ||
| : 'vi'; | ||
| (process.platform === 'win32' ? 'notepad' : 'vi'); |
There was a problem hiding this comment.
While this change correctly fixes the operator precedence issue, it's still vulnerable to issues if VISUAL or EDITOR are set to an empty or whitespace-only string. The nullish coalescing operator (??) will resolve to such strings, which then causes spawn to fail.
To make this more robust, I suggest trimming the environment variables and using the logical OR (||) operator. This ensures that empty or whitespace-only values are treated as "unset", correctly falling back to the next option in the chain. This aligns with the general rule to 'trim the optional string and use the fallback if the result is empty'.
| command = | |
| (process.env['VISUAL'] ?? | |
| process.env['VISUAL'] ?? | |
| process.env['EDITOR'] ?? | |
| process.platform === 'win32') | |
| ? 'notepad' | |
| : 'vi'; | |
| (process.platform === 'win32' ? 'notepad' : 'vi'); | |
| command = | |
| process.env['VISUAL']?.trim() || | |
| process.env['EDITOR']?.trim() || | |
| (process.platform === 'win32' ? 'notepad' : 'vi'); |
References
- When using an optional string with a fallback value, trim the optional string and use the fallback if the result is empty to avoid uninformative messages from whitespace-only strings.
|
Size Change: 0 B Total Size: 23.2 MB ℹ️ View Unchanged
|
|
/patch |
|
✅ Patch workflow(s) dispatched successfully! 📋 Details:
🔗 Track Progress: |
|
❌ Patch creation failed! There was an error creating the patch release. 🔍 Troubleshooting:
🔗 Links: |
|
❌ Patch creation failed! There was an error creating the patch release. 🔍 Troubleshooting:
🔗 Links: |
1 similar comment
|
❌ Patch creation failed! There was an error creating the patch release. 🔍 Troubleshooting:
🔗 Links: |
|
❌ Patch creation failed! There was an error creating the patch release. 🔍 Troubleshooting:
🔗 Links: |
|
🚀 Patch PR Created! 📋 Patch Details:
📝 Next Steps:
🔗 Track Progress: |
|
🚀 Patch Release Started! 📋 Release Details:
⏳ Status: The patch release is now running. You'll receive another update when it completes. 🔗 Track Progress: |
|
✅ Patch Release Complete! 📦 Release Details:
🎉 Status: Your patch has been successfully released and published to npm! 📝 What's Available:
🔗 Links: |
Summary
Fix bad fallback logic for opening external editors.
Details
This was broken in #16556
How to Validate
hit ctrl-x without an editor configured.
Pre-Merge Checklist