Skip to content

Commit b159ae2

Browse files
authored
Fix environment variables leaking into the parent environment (#1078)
* Add a test against issue #1076 * Test against a single server, not all of them * Fix the issue by using `os._Environ.copy()` * Add changelog entry * Bump version to 2.2.5
1 parent acc0d74 commit b159ae2

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Changelog
22

3+
### `jupyter-lsp 2.2.5`
4+
5+
- bug fixes:
6+
- fix for environment variables leaking into the parent environment (#1078)
7+
38
### `jupyter-lsp 2.2.4`
49

510
- bug fixes:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
""" single source of truth for jupyter_lsp version
22
"""
33

4-
__version__ = "2.2.4"
4+
__version__ = "2.2.5"

python_packages/jupyter_lsp/jupyter_lsp/session.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import os
77
import string
88
import subprocess
9-
from copy import copy
109
from datetime import datetime, timezone
1110

1211
from tornado.ioloop import IOLoop
@@ -161,7 +160,7 @@ def init_writer(self):
161160
)
162161

163162
def substitute_env(self, env, base):
164-
final_env = copy(os.environ)
163+
final_env = base.copy()
165164

166165
for key, value in env.items():
167166
final_env.update({key: string.Template(value).safe_substitute(base)})

python_packages/jupyter_lsp/jupyter_lsp/tests/test_session.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import os
23

34
import pytest
45

@@ -100,3 +101,25 @@ async def test_ping(handlers):
100101
assert ws_handler._ping_sent is True
101102

102103
ws_handler.on_close()
104+
105+
106+
@pytest.mark.asyncio
107+
async def test_substitute_env(handlers):
108+
"""should not leak environment variables"""
109+
a_server = "pylsp"
110+
111+
handler, ws_handler = handlers
112+
manager = handler.manager
113+
114+
manager.initialize()
115+
116+
await assert_status_set(handler, {"not_started"})
117+
118+
await ws_handler.open(a_server)
119+
session = manager.sessions[ws_handler.language_server]
120+
new_env = session.substitute_env({"test-variable": "value"}, os.environ)
121+
122+
assert "test-variable" in new_env
123+
assert "test-variable" not in os.environ
124+
125+
ws_handler.on_close()

0 commit comments

Comments
 (0)