Skip to content

Commit

Permalink
Accept environment variables with different cases on Windows. Fixes #607
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed May 28, 2021
1 parent ab4b969 commit 4cdf243
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
10 changes: 0 additions & 10 deletions src/debugpy/launcher/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ def property_or_debug_option(prop_name, flag_name):

env = os.environ.copy()
env_changes = request("env", json.object((unicode, type(None))))
if sys.platform == "win32":
# Environment variables are case-insensitive on Win32, so we need to normalize
# both dicts to make sure that env vars specified in the debug configuration
# overwrite the global env vars correctly. If debug config has entries that
# differ in case only, that's an error.
env = {k.upper(): v for k, v in os.environ.items()}
n = len(env_changes)
env_changes = {k.upper(): v for k, v in env_changes.items()}
if len(env_changes) != n:
raise request.isnt_valid('Duplicate entries in "env"')
if "DEBUGPY_TEST" in env:
# If we're running as part of a debugpy test, make sure that codecov is not
# applied to the debuggee, since it will conflict with pydevd.
Expand Down
9 changes: 5 additions & 4 deletions tests/debugpy/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ def code_to_debug():
else:
assert env[varname] == "42"
elif sys.platform == "win32":
# On Win32, variable names are case-insensitive, so debug config should
# replace the global env var even if there is a case mismatch.
# On Win32, although variable names are case-insensitive for matching, they're still
# case-preserving (and it's even possible to have something as Path and PATH even
# though later on one would override the other).
assert varname.lower() not in env
if new_value is None:
assert varname not in env
assert env[varname] == "1"
else:
assert env[varname] == "42"
assert varname.lower() not in env
else:
# On other platforms, variable names are case-sensitive, so case mismatch
# should result in two different variables.
Expand Down

0 comments on commit 4cdf243

Please sign in to comment.