Skip to content

Merge env keys that differ only in case on Windows - #1160

Open
Arnab Chatterjee (ArnabOPP) wants to merge 2 commits into
microsoft:mainfrom
ArnabOPP:fix/261-duplicate-env-path-case
Open

Arnab Chatterjee (ArnabOPP) wants to merge 2 commits into
microsoft:mainfrom
ArnabOPP:fix/261-duplicate-env-path-case

Conversation

@ArnabOPP

Copy link
Copy Markdown

Refs #261

On Windows the debug env can end up containing both Path and PATH (the code appends to Path, while an incoming env may already carry PATH). debugpy treats Windows env names as case-insensitive and rejects this with Found duplicate in "env": PATH.

This adds normalizeEnvironmentVariableCase and applies it at the end of getDebugEnvironmentVariables. On Windows only:

  • Path/PATH are merged into a single Path entry, with duplicate directories removed.
  • Any other keys differing only in case keep the last value.

Other platforms are unchanged.

Notes:

  • I couldn't reproduce the original error; other reports in the issue point to different causes (malformed system Path entries, reboot), so this may not cover every case.
  • Added unit tests in helper.unit.test.ts. Typecheck and lint pass. I couldn't run the full mocha suite locally (the VS Code test host fails on a path containing spaces), so I'm relying on CI for that.

🤖 Generated with Claude Code

On Windows the debug env can end up with both "Path" and "PATH", which
debugpy rejects with 'Found duplicate in "env": PATH'. Normalize such
keys before handing the configuration to the debug adapter, merging the
distinct PATH entries.

Refs microsoft#261

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ArnabOPP

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Windows environment merging can discard explicit launch values and place system PATH entries before launch-configured directories, violating source precedence and potentially selecting the wrong executable.

2 open issues
What changed in this PR

This PR targets debugpy’s duplicate environment-key rejection on Windows (#261) by normalizing the environment passed to debug launches.

Changes:

  • Merges case variants of PATH, removing duplicate directory entries.
  • Keeps the last value for other case-colliding keys on Windows; leaves other platforms unchanged.
  • Adds unit tests for PATH merging, last-value behavior, and non-Windows handling.
File Description
src/​test/​unittest/​configuration/​resolvers/​helper.unit.test.ts Adds focused environment-normalization tests.
src/​extension/​debugger/​configuration/​resolvers/​helper.ts Adds Windows key normalization and applies it to the completed debug environment.

Review effort: Balanced

}

return env;
return normalizeEnvironmentVariableCase(env);
const current = env[key];
let merged = current;
if (upper === 'PATH' && typeof previous === 'string' && typeof current === 'string') {
const entries = [...previous.split(';'), ...current.split(';')].filter(
Address review feedback: instead of collapsing case-colliding keys at
the end, canonicalize each env source (launch env, env file) first and
make mergeVariables case-insensitive on Windows. This keeps
launch > env file > system precedence for ordinary variables, and keeps
user-supplied PATH entries ahead of the system PATH.

Adds getDebugEnvironmentVariables regression tests for both cases.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ArnabOPP

Copy link
Copy Markdown
Author

Thanks for the review. Both points are addressed in 77e0b0f:

  • Source precedence: env sources (launch env, env file) are now canonicalized before they're combined, and mergeVariables matches names case-insensitively on Windows, so launch > env file > system holds for names that differ only in case (e.g. launch foo now beats inherited FOO).
  • PATH ordering: all spellings of the search path become a single Path key, so user-supplied entries (env file, then launch) come before the system PATH.

Added getDebugEnvironmentVariables regression tests for both scenarios.

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.

2 participants