Skip to content

Environment collection replace API strips equals sign at the end #197603

@xEverth

Description

@xEverth

VS Code version: Code - Insiders 1.84.0-insider (35419fc, 2023-10-27T10:41:08.734Z)
OS version: Windows_NT x64 10.0.19045

Try applying these variables using the environment collection API:

TEST_KEY="SOMETHING"
TEST_KEY_2="SOMETHING="
TEST_KEY_3=SOMETHING=
TEST_KEY_4='SOMETHING='

Even though screenshot says they're applied as expected:

image

equal sign is stripped from the end when printing the value:

image

Original bug report


Type: <b>Bug</b>

<!-- Please fill in all XXX markers -->
# Behaviour
## Expected vs. Actual

Expected:
Environment keys are read correctly, both in powershell and in python

Actual
When the .env file is set in the Python extension configuration, if the keys have equals sign they are stripped out, whether they are quoted or not. This happens both if the .env file is the default ${workspaceFolder}/.env or if this is changed. When the environments variables are loaded by the extension, this may change the behaviour of programs which use os.getenv("KEY") to retrieve the values.

## Steps to reproduce:

1. Have a .env file with the following content:

TEST_KEY="SOMETHING"
TEST_KEY_2="SOMETHING="
TEST_KEY_3=SOMETHING=
TEST_KEY_4='SOMETHING='

2) Set the path to this .env file in the Python extension settings (Python:Env File)

3) Open a new terminal (Powershell/Windows)

4) Check the value of the environment variables with $env:PATH

5) See that the '=' character at the end is stripped

6) Open a python interpreter and attempt loading the environment file again (python-dotenv)

7) The equal signs are still stripped

<!--
**After** creating the issue on GitHub, you can add screenshots and GIFs of what is happening. Consider tools like https://www.cockos.com/licecap/, https://github.com/phw/peek or https://www.screentogif.com/ for GIF creation.
-->

<!-- **NOTE**: Everything below except Python output panel is auto-generated; no editing required. Please do provide Python output panel. -->
# Diagnostic data

-   Python version (& distribution if applicable, e.g. Anaconda): 3.11.0
-   Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
-   Value of the `python.languageServer` setting: Pylance

<details>

<summary>Output for <code>Python</code> in the <code>Output</code> panel (<code>View</code>→<code>Output</code>, change the drop-down the upper-right of the <code>Output</code> panel to <code>Python</code>)
</summary>

<p>

From a python interpreter

from dotenv import load_dotenv; import os
with open(".env", "r") as f:
f.readlines()
os.getenv("TEST_KEY")
os.getenv("TEST_KEY_2")
os.getenv("TEST_KEY_3")
os.getenv("TEST_KEY_4")

This may print out SOMETHING in all 4 cases, without the = sign

Repeat after deactivating the environment variable loading from the Python extension and see the = sign for TEST_KEY_2, TEST_KEY_3 and TEST_KEY_4


</p>
</details>

<details>

<summary>User Settings</summary>

<p>

envFile: ""

venvPath: ""

venvFolders: ""

languageServer: "Pylance"

testing
• unittestEnabled: true

experiments
• optInto: ["pythonTerminalEnvVarActivation"]


</p>
</details>


Extension version: 2023.18.0
VS Code version: Code - Insiders 1.84.0-insider (35419fc016b8d3d5dbc59aa11a0be957b0897309, 2023-10-27T10:41:08.734Z)
OS version: Windows_NT x64 10.0.19045
Modes:

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i7-10875H CPU @ 2.30GHz (16 x 2304)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: enabled_on<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>video_decode: enabled<br>video_encode: enabled<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled<br>webgpu: enabled|
|Load (avg)|undefined|
|Memory (System)|31.84GB (16.35GB free)|
|Process Argv|--log trace|
|Screen Reader|no|
|VM|0%|
</details>
<!-- generated by issue reporter -->

Metadata

Metadata

Assignees

Labels

bugIssue identified by VS Code Team member as probable bugterminalGeneral terminal issues that don't fall under another labelterminal-shell-bashAn issue in the terminal specific to bash, including shell integrationterminal-shell-fishAn issue in the terminal specific to fish, including shell integrationterminal-shell-integrationShell integration infrastructure, command decorations, etc.terminal-shell-pwshAn issue in the terminal specific to PowerShell, including shell integrationverifiedVerification succeeded

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions