From 4cdf243406fb0ba412eb2e05d96d6be7fab6843b Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Fri, 28 May 2021 11:40:23 -0300 Subject: [PATCH] Accept environment variables with different cases on Windows. Fixes #607 --- src/debugpy/launcher/handlers.py | 10 ---------- tests/debugpy/test_env.py | 9 +++++---- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/debugpy/launcher/handlers.py b/src/debugpy/launcher/handlers.py index da12ed077..0303741d1 100644 --- a/src/debugpy/launcher/handlers.py +++ b/src/debugpy/launcher/handlers.py @@ -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. diff --git a/tests/debugpy/test_env.py b/tests/debugpy/test_env.py index 09fc7919c..7d7f44dc5 100644 --- a/tests/debugpy/test_env.py +++ b/tests/debugpy/test_env.py @@ -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.