git-for-windows / git

A fork of Git containing Windows-specific patches.
http://gitforwindows.org/
Other
8.34k stars 2.53k forks source link

Git Bash on Windows misinterprets escape sequences #5217

Open dmelikhov opened 7 hours ago

dmelikhov commented 7 hours ago

Setup

$ git --version --build-options
git version 2.47.0.windows.1
cpu: x86_64
built from commit: d53e4648cb65eb75dd8d8a093d17400a18a9a15d
sizeof-long: 4
sizeof-size_t: 8
shell-path: D:/git-sdk-64-build-installers/usr/bin/sh
feature: fsmonitor--daemon
libcurl: 8.10.1
OpenSSL: OpenSSL 3.2.3 3 Sep 2024
zlib: 1.3.1
$ cmd.exe /c ver
Microsoft Windows [Version 10.0.22631.4317]
(c) Microsoft Corporation. All rights reserved.
$ cat /etc/install-options.txt
Editor Option: SublimeText
Custom Editor Path:
Default Branch Option:
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: LFOnly
Bash Terminal Option: MinTTY
Git Pull Behavior Option: FFOnly
Use Credential Manager: Enabled
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable FSMonitor: Disabled

Details

I'm writing a cross-platform nodejs script that executes bash commands. It should work the same way on Linux/MacOS/Windows, but on my Windows machine with Git Bash there seems to be an issue with escape sequences.

While trying out the child_process.spawn function, I encountered a strange behavior that I was able to reproduce in Windows cmd.exe:

d:\>bash -c "echo $'this is \a test'"
this is  test

d:\>bash -c "echo $'this is \\a test'"
this is  test

The first output is expected, but in the second it looks like \\a is treated as the \a escape sequence.

Running the same commands in an interactive bash session yields correct results:

$ echo $'this is \a test'
this is  test

$ echo $'this is \\a test'
this is \a test
dmelikhov commented 7 hours ago

Please also see related issue: https://github.com/google/zx/issues/873