fix(tools): preserve raw paths and regex escapes for ripgrep on Windows - #69183
fix(tools): preserve raw paths and regex escapes for ripgrep on Windows#69183rille111 wants to merge 1 commit into
Conversation
Related to #63458 and #67914 for #63177. The patches overlap on native rg path preservation but differ in scope: this one also changes regex, grep, and Python snippet quoting, while #67914 normalizes native-executable paths. Please choose one cross-command policy. |
|
This PR intentionally addresses both path preservation for native Windows executables like rg.exe and escaping for regex patterns/python snippets. On MSYS/Git Bash on Windows, passing regex patterns through MSYS path normalization alters backslashes (for example \d turning into /d), which causes search query failures regardless of whether the target path itself is normalized. Standardizing on _escape_shell_raw for non-path strings and native CLI inputs provides a consistent cross-command policy across ripgrep, grep, and inline python invocation. |
|
Native Windows note: live-verified the underlying bug on current One caution on The idea of not MSYS-rewriting regex patterns ( |
|
Update for reviewers/triage: Per the #63177 follow-up and discussion on #67914 (comment), maintainers are consolidating the complementary halves:
That matches @monerostar's earlier note here: path args should use forward-slash native I'll close this PR as superseded once #67914 includes the pattern portion (or once it merges). No further changes planned on this branch unless maintainers want the adjacent |
Add _escape_pattern_arg and use it for rg + grep patterns so backslash regex escapes (\w, \d, \() are preserved and not mangled into forward slashes on Windows. Consolidates the pattern portion of NousResearch#69183 per the NousResearch#63177 split (path handling stays in this PR's _escape_native_exe_arg). Co-authored-by: rille111 <rille111@users.noreply.github.com>
Duplicate of #67914 for the Windows rg repair: its current head carries the pattern-escaping work and adds receiver-aware native-path conversion. The remaining python-delete idea can be proposed separately if needed. |
|
Superseded by #67914. The receiver-aware path fix already lived there; the narrow pattern portion from this PR ( No further work planned here. Thanks @Bartok9 @lifeFedorovAlexey @monerostar for the split. |
Superseded by the open consolidation #67914, which carries the regex/pattern escape work and uses receiver-aware native-path handling for the Windows rg repair. |
|
Thanks all — happy to see the pattern-escaping half land in #67914 with the receiver-aware native-path handling. Agreed that #67914's forward-slash native |
Add _escape_pattern_arg and use it for rg + grep patterns so backslash regex escapes (\w, \d, \() are preserved and not mangled into forward slashes on Windows. Consolidates the pattern portion of NousResearch#69183 per the Co-authored-by: rille111 <rille111@users.noreply.github.com> (cherry picked from commit b012329)
Fixes an issue on Windows where search_files with ripgrep failed with
rg: /c/...: The system cannot find the path specified. (os error 3).Root Cause
When searching paths or executing non-path strings across Git Bash MSYS on Windows,
_escape_shell_argpreviously ran_bash_safe_path()on all arguments. This converted drive roots (C:/...,B:/...) into POSIX paths (/c/...,/b/...) and mangled backslashes in regex search queries (such as\d+becoming/d+).While POSIX shell builtins require MSYS path conversion, native Windows binaries like
rg.exeexpect native drive paths (C:/...) and raw regex strings.Solution
_escape_shell_rawto quote non-path arguments and native CLI tool arguments without running MSYS path translation._search_with_rgand_search_files_rgto use_escape_shell_rawfor search patterns, python scripts, and ripgrep search paths._escape_shell_rawand Windows path preservation in ripgrep search execution.