Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix environment variables leaking into the parent environment #1078

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading