Title: Fix multiline environment variable parsing in .env files by Copilot · Pull Request #928 · microsoft/vscode-python-debugger · GitHub
Open Graph Title: Fix multiline environment variable parsing in .env files by Copilot · Pull Request #928 · microsoft/vscode-python-debugger
X Title: Fix multiline environment variable parsing in .env files by Copilot · Pull Request #928 · microsoft/vscode-python-debugger
Description: Fix multiline environment variable parsing in .env files
The envFile parser was truncating quoted multiline values at the first newline. A value like:
EXAMPLE_VAR='very long value
with new line , we need to get all the lines'
Would parse as 'very long value instead of preserving the full multiline content.
Changes Made:
Analyze the current parseEnvFile and parseEnvLine implementation
Implement a stateful parser that handles multiline quoted values
Uses character-by-character parsing with state tracking for quotes
Preserves newlines within quoted values
Handles both single and double quotes
Improved escape sequence handling to properly count consecutive backslashes
Add comprehensive tests for multiline environment variables
Single-quoted multiline values
Double-quoted multiline values
Escaped newlines (\n)
Multiple multiline variables
Mix of multiline and single-line values
Trailing whitespace preservation
Verify the fix works with the example from the issue
Tested with actual .env file from the issue
Output matches python-dotenv library behavior
Address code review feedback
Improved escape sequence detection (counts consecutive backslashes)
Verified trailing whitespace is preserved correctly
Fixed comment about regex 's' flag usage
Verified existing tests still pass (lint and build successful)
Security check passed (CodeQL found no vulnerabilities)
Fixed linter and prettier formatting issues
Solution:
The fix replaces the simple .split('\n') approach with a state machine that:
Tracks whether we're inside quotes (single or double)
Preserves newlines when inside quotes
Only splits on newlines when not inside quotes
Properly handles escaped quotes by counting consecutive backslashes
Resets state properly between lines
This matches the behavior of the python-dotenv library that the issue mentions works correctly.
Testing:
All tests pass, including:
Original issue example works correctly
Multiline values in single and double quotes
Escaped newlines (\n sequences)
Multiple multiline variables
Trailing whitespace preservation
Build and lint successful
CodeQL security scan passed with no alerts
Prettier formatting applied
Security Summary:
No security vulnerabilities introduced. CodeQL analysis found 0 alerts.
Original prompt
This section details on the original issue you should resolve
Open Graph Description: Fix multiline environment variable parsing in .env files The envFile parser was truncating quoted multiline values at the first newline. A value like: EXAMPLE_VAR='very long value with new line...
X Description: Fix multiline environment variable parsing in .env files The envFile parser was truncating quoted multiline values at the first newline. A value like: EXAMPLE_VAR='very long value with new ...
Opengraph URL: https://github.com/microsoft/vscode-python-debugger/pull/928
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:b927a240-aa58-2598-63da-3edca5d79a10 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E64E:395B76:48ABA4:5E7F50:697F420F |
| html-safe-nonce | 0172e61f7c080780fe602814578aa4bcbdfa3af32f3f9157aeb3f991797ab33f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNjRFOjM5NUI3Njo0OEFCQTQ6NUU3RjUwOjY5N0Y0MjBGIiwidmlzaXRvcl9pZCI6IjcyODA3MDYwNDI0NjE3MjE3NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 39ad40473184e4d58a6e03bf8a04a7a919e2c409828d286b644ec4c5287eb70b |
| hovercard-subject-tag | pull_request:3175445693 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/microsoft/vscode-python-debugger/pull/928/files |
| twitter:image | https://avatars.githubusercontent.com/in/1143301?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/in/1143301?s=400&v=4 |
| og:image:alt | Fix multiline environment variable parsing in .env files The envFile parser was truncating quoted multiline values at the first newline. A value like: EXAMPLE_VAR='very long value with new line... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 60279d4097367e16897439d16d6bbe4180663db828c666eeed2656988ffe59f6 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/microsoft/vscode-python-debugger git https://github.com/microsoft/vscode-python-debugger.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 615045081 |
| octolytics-dimension-repository_nwo | microsoft/vscode-python-debugger |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 615045081 |
| octolytics-dimension-repository_network_root_nwo | microsoft/vscode-python-debugger |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7c85641c598ad130c74f7bcc27f58575cac69551 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width