-
Notifications
You must be signed in to change notification settings - Fork 9.6k
fix(core): Preserve escaped characters in gitignore patterns #11171
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
Conversation
Summary of ChangesHello @EricRahm, 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 addresses a critical bug in the gitignore parser where patterns containing backslash-escaped characters were misinterpreted. The root cause was an overzealous path normalization step that inadvertently corrupted these escape sequences. The fix involves removing the problematic string replacement and adopting 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.
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 effectively addresses a bug in the gitignore parser where backslash-escaped characters were being incorrectly processed. The root cause was an aggressive path normalization step that replaced all backslashes, which corrupted escape sequences in gitignore patterns. The fix correctly removes this string replacement and switches to using path.posix.join for path manipulation. This ensures that paths consistently use forward slashes, as expected by the underlying ignore library, without corrupting the patterns. The addition of a specific test case for escaped characters is excellent, as it directly validates the fix. The changes are well-targeted and correctly resolve the issue.
| @@ -89,9 +92,6 @@ export class GitIgnoreParser implements GitIgnoreFilter { | |||
| newPattern = '!' + newPattern; | |||
| } | |||
|
|
|||
| // Even in windows, Ignore expects forward slashes. | |||
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.
have you tested this on windows? need to make sure these changes do not break windows support.
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.
Thanks for the quick review, I'm getting a windows dev environment setup and will report back!
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.
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.
I now have a windows machine setup and have tested this locally.
I added three files with special names:
packages/core/#foo.jspackages/core/src/tools/#foo.jspackages/core/src/utils/#foo.js
I setup my .gitignore to ignore all #foo.js (this requires an escape character) by default but explicitly allow two of the files:
\#foo.js
!packages/core/#foo.js
!packages/core/src/utils/#foo.js
I then asked gemini-cli to find all the #foo.js files, we see it find the 2 that are allowed, but it does not find the 3rd as expected by the the .gitignore configuration.
jacob314
left a comment
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.
The gitignore parser was incorrectly processing patterns containing backslash-escaped characters (e.g., `\#`, `\!`, '\ '). This was caused by an aggressive path normalization step that replaced all backslashes with forward slashes, corrupting the escape sequence before it could be interpreted by the `ignore` library. This resulted in patterns intended to ignore files with special names (like `#foo`) being misinterpreted, causing those files to be incorrectly processed instead of ignored. This commit addresses the issue by: - Removing the incorrect string replacement for path normalization. - Switching to `path.posix.join` for path manipulation to ensure consistent, cross-platform behavior with forward slashes, as expected by the underlying `ignore` library. These changes ensure that escaped patterns are passed to the `ignore` library unmodified, restoring the correct gitignore behavior as specified in the gitignore man pages.
9f9781d to
baa00d1
Compare
…gemini#11171) Co-authored-by: Jacob Richman <[email protected]>


The gitignore parser was incorrectly processing patterns containing backslash-escaped characters (e.g.,
\#,\!, '\ '). This was caused by an aggressive path normalization step that replaced all backslashes with forward slashes, corrupting the escape sequence before it could be interpreted by theignorelibrary.This resulted in patterns intended to ignore files with special names (like
#foo) being misinterpreted, causing those files to be incorrectly processed instead of ignored.This commit addresses the issue by:
path.posix.joinfor path manipulation to ensure consistent, cross-platform behavior with forward slashes, as expected by the underlyingignorelibrary.These changes ensure that escaped patterns are passed to the
ignorelibrary unmodified, restoring the correct gitignore behavior as specified in the gitignore man pages.TLDR
The gitignore parser is replacing ignore pattern escape sequences with forward slashes.
Dive Deeper
The gitignore parser was incorrectly processing patterns containing backslash-escaped characters (e.g.,
\#,\!, '\ '). This was caused by an aggressive path normalization step that replaced all backslashes with forward slashes, corrupting the escape sequence before it could be interpreted by theignorelibrary.This resulted in patterns intended to ignore files with special names (like
#foo) being misinterpreted, causing those files to be incorrectly processed instead of ignored.This commit addresses the issue by:
path.posix.joinfor path manipulation to ensure consistent, cross-platform behavior with forward slashes, as expected by the underlyingignorelibrary.These changes ensure that escaped patterns are passed to the
ignorelibrary unmodified, restoring the correct gitignore behavior as specified in the gitignore man pages.Reviewer Test Plan
Testing Matrix
Linked issues / bugs
Fixes #11168