Repository navigation
Keep backslashes in the pager command on Windows - #4104
Conversation
c4a5c8d to
8e4017f
Compare
rahul05ranjan
left a comment
There was a problem hiding this comment.
The premise is real and I reproduced it: POSIX-style splitters treat \ as an escape, so shlex.split("C:\\tools\\less.exe") yields C:toolsless.exe — the same escape semantics shell_words applies, which is exactly the "Pager 'C:toolsless.exe' not found" failure you describe. A backslash-preserving splitter for Windows is the right fix, and keeping shell_words on other platforms avoids changing behavior for users who legitimately rely on POSIX quoting there.
I also replicated split_command_windows line by line and checked all seven cases in your unit-test table plus the error path — every one behaves as asserted, including the trickier ones (quote opening mid-word for --prompt="a b", the empty "" argument, and the unclosed-quote ParseError). The ParseError return type is already imported at the top of pager.rs, so that's clean.
Design details worth calling out positively:
- Using
if cfg!(windows)rather than#[cfg]means the windows splitter's unit tests still compile and run on the Linux CI, where they actually get exercised — good choice. - Quotes doing pure grouping (no escape processing inside) is the correct simplification here; pager commands don't need
$(...)-style semantics on Windows.
One nit on the integration test: pager_windows_absolute_path builds BAT_PAGER as format!("{} pager-output", pager.display()) without quoting the path. On a checkout located under a path containing spaces (local dev machines hit this, e.g. C:\Users\Some Name\...), the split yields C:\Users\Some as the binary and the test fails even though the code is correct. Wrapping it as format!("\"{}\" pager-output", pager.display()) would make the test space-proof and also exercise the quoted-path form end to end.
8e4017f to
0318353
Compare
|
Perhaps worth fixing the nit mentioned in #4104 (review), and before I merge, I just want to sanity check something - what happens when using ie. Mintty or some other unix terminal emulator on Windows? Is it possible that then posix path separators should and escape chars should be honored but no longer would be with this PR? |
A checkout under a path with spaces split the unquoted path at the first space. Quoting it also covers the quoted-path form end to end.
|
Merged master (5754e83) and quoted the path in On Mintty: bat starts the pager with
|
|
Thanks @jaeminbird — quoting the path in |
The config file and BAT_OPTS were split with shell_words, which treats a backslash as an escape, so --pager=C:\tools\less.exe became C:toolsless.exe. Split them with the same function as the pager command, which keeps backslashes on Windows since #4104. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The pager command (
BAT_PAGER,PAGER,--pager) is split withshell_words, which treats\as an escape, so on WindowsBAT_PAGER=C:\tools\less.exebecomesC:toolsless.exeand bat warns "Pager 'C:toolsless.exe' not found, outputting to stdout instead". The README suggests pointing an environment variable at a downloadedless.exe, which hits this directly. On Windows the command is now split on whitespace with single and double quotes, keeping\literally; other platforms still useshell_words.pager_windows_absolute_path(absolute path to the mockedecho.bat) fails before the change and passes after.BAT_PAGER=C:\Windows\System32\more.com.cargo test, clippy and fmt pass.