Skip to content

Commit

Permalink
Fix environment variables leaking into the parent environment (#1078)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
krassowski authored Apr 9, 2024
1 parent acc0d74 commit b159ae2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Changelog

### `jupyter-lsp 2.2.5`

- bug fixes:
- fix for environment variables leaking into the parent environment (#1078)

### `jupyter-lsp 2.2.4`

- bug fixes:
Expand Down
2 changes: 1 addition & 1 deletion python_packages/jupyter_lsp/jupyter_lsp/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" single source of truth for jupyter_lsp version
"""

__version__ = "2.2.4"
__version__ = "2.2.5"
3 changes: 1 addition & 2 deletions python_packages/jupyter_lsp/jupyter_lsp/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os
import string
import subprocess
from copy import copy
from datetime import datetime, timezone

from tornado.ioloop import IOLoop
Expand Down Expand Up @@ -161,7 +160,7 @@ def init_writer(self):
)

def substitute_env(self, env, base):
final_env = copy(os.environ)
final_env = base.copy()

for key, value in env.items():
final_env.update({key: string.Template(value).safe_substitute(base)})
Expand Down
23 changes: 23 additions & 0 deletions python_packages/jupyter_lsp/jupyter_lsp/tests/test_session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import os

import pytest

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

ws_handler.on_close()


@pytest.mark.asyncio
async def test_substitute_env(handlers):
"""should not leak environment variables"""
a_server = "pylsp"

handler, ws_handler = handlers
manager = handler.manager

manager.initialize()

await assert_status_set(handler, {"not_started"})

await ws_handler.open(a_server)
session = manager.sessions[ws_handler.language_server]
new_env = session.substitute_env({"test-variable": "value"}, os.environ)

assert "test-variable" in new_env
assert "test-variable" not in os.environ

ws_handler.on_close()

0 comments on commit b159ae2

Please sign in to comment.