Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 1, 2025

User reported that FOO=bar # trailing comment in .env files was including the comment in the value. Investigation confirmed the current dotenv 16.4.5 dependency handles inline comments correctly (support added in v15.0.0).

Changes

  • Added comprehensive unit tests for parseEnvFile and mergeEnvVariables in envVarUtils.ts
  • Tests verify trailing comments are stripped from unquoted values
  • Tests verify hash characters inside quotes are preserved (expected behavior)
  • Edge cases covered: empty files, CRLF line endings, export prefixes, multi-line configs

Test Coverage

// Trailing comments stripped
'FOO=bar  # comment'  { FOO: 'bar' }

// Hash preserved in quotes
'FOO="bar  # not a comment"'  { FOO: 'bar  # not a comment' }

The reported issue may have been a regression in an older extension version or a quoted value scenario. These tests prevent future regressions.

Original prompt

This section details on the original issue you should resolve

<issue_title>envFile configuration wrongly includes a trailing comment in environment variable value</issue_title>
<issue_description># Description
I defined an environment variable with a trailing comment in my .env file.

FOO=bar  # trailing comment

When debugging the following python module.

import os

foo = os.getenv("FOO")
print(foo)

foo gets value bar # trailing comment, the expected behaviour is foo has value bar.

Image

Version

I am using MacOS and I have the following extensions:

Name: Python Environments
Id: ms-python.vscode-python-envs
Description: Provides a unified python environment experience
Version: 1.12.0
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-python-envs
Name: Python Debugger
Id: ms-python.debugpy
Description: Python Debugger extension using debugpy.
Version: 2025.16.0
Publisher: Microsoft
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.debugpy

</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 1, 2025 19:45
Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com>
Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix envFile configuration to remove trailing comments Add unit tests for envFile trailing comment handling Dec 1, 2025
Copilot AI requested a review from anthonykim1 December 1, 2025 19:50
Copilot finished work on behalf of anthonykim1 December 1, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

envFile configuration wrongly includes a trailing comment in environment variable value

2 participants