Skip to content
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

\ path separators are interpreted as escape sequences when HOME is set in bash terminal #240539

Open
abrahan-munro opened this issue Feb 12, 2025 · 6 comments · May be fixed by #240614
Open

\ path separators are interpreted as escape sequences when HOME is set in bash terminal #240539

abrahan-munro opened this issue Feb 12, 2025 · 6 comments · May be fixed by #240614
Assignees
Labels
confirmation-pending terminal-shell-git-bash An issue in the terminal specific to git bash on Windows, including shell integration
Milestone

Comments

@abrahan-munro
Copy link

abrahan-munro commented Feb 12, 2025

Type: Bug

Behaviour

\ path separators are interpreted as escape sequences when HOME is set in bash terminal

Steps to reproduce:

  1. When running git bash outside of vscode, or when starting and using the vscode bash terminal while the python extension is disabled, HOME is set correctly: [output is reformatted slightly for compactness]
$ echo -E "$HOME" | od -c
/ c / U s e r s / a b r a h a n \n
  1. When starting and using the vscode bash terminal while the python extension is enabled, HOME is set incorrectly:
$ echo -E "$HOME" | od -c
C : \ U s e r s \a b r a h a n \n

That is, the path separators have been interpreted as escape codes, so the 2 character sequence \ and a has become a single control character \a. Also, it is using the C:\ form rather than /c/.

Diagnostic data

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

2025-02-12 14:53:47.380 [info] Setting environment variable HOME in collection to C:\Users\abrahan {"applyAtShellIntegration":true,"applyAtProcessCreation":true}

Extension version: 2025.0.0
VS Code version: Code 1.96.4 (cd4ee3b, 2025-01-16T00:16:19.038Z)
OS version: Windows_NT x64 10.0.19045
Modes:

@abrahan-munro
Copy link
Author

Here's a work around.

The automatic setting of environment variables happens after shell startup, so we can't work around this in the shell configuration alone. However it can be done by disabling terminal shell integration automatic script injection, and preserving and restoring HOME either side of terminal shell integration manual installation:

  1. Control-Shift-P, Preferences: Open User Settings (JSON).
  2. Add "terminal.integrated.shellIntegration.enabled": false.
  3. Run code ~/.bashrc in Git Bash to open the file in VS Code.
  4. Add the following to your ~/.bashrc file:
if [ "$TERM_PROGRAM" == "vscode" ]
then
    tmp="$HOME"
    . "$(code --locate-shell-integration-path bash)"
    HOME="$tmp"
fi

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Feb 12, 2025
Copy link

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.97.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@Tyriar Tyriar added confirmation-pending terminal-shell-git-bash An issue in the terminal specific to git bash on Windows, including shell integration labels Feb 12, 2025
@Tyriar Tyriar added this to the Backlog milestone Feb 12, 2025
@abrahan-munro
Copy link
Author

karthiknadig
transferred this issue frommicrosoft/vscode-python

Note that Extension Bisect identified the Python extension as the cause.

@abrahan-munro
Copy link
Author

the latest stable release is 1.97.1. Please try upgrading to the latest version and checking whether this issue remains.

Thanks, yes it is still present in 1.97.1. It is also present in 1.98.0-insider.

@abrahan-munro
Copy link
Author

In shellIntegration-bash.sh, VSCODE_ENV_REPLACE is : separated and in the values : has been escaped by being replaced with \x3a, so the echo -e is to convert \x3a back to :. But since any \ in the values haven't been escaped, they get mistakenly interpreted as escape codes. To fix it, any \ in the values should be replaced with \\. Alternatively, if it's only : being escaped, it can be fixed by relacing this line with:

VALUE="$(echo "$ITEM" | cut -d "=" -f 2- | sed 's/\\x3a/:/g')"

@abrahan-munro
Copy link
Author

@Tyriar here is where the bug was introduced. Only : is escaped. \ should also be escaped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmation-pending terminal-shell-git-bash An issue in the terminal specific to git bash on Windows, including shell integration
Projects
None yet
3 participants