Skip to content

Commit 98eff01

Browse files
authored
Merge pull request #437 from diocas/main
Fix double formatting of callables (`command`, `environment`, `request_headers_override`)
2 parents 8a4d62b + 40a37b3 commit 98eff01

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

jupyter_server_proxy/handlers.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,7 @@ def _render_template(self, value):
654654
def _realize_rendered_template(self, attribute):
655655
"""Call any callables, then render any templated values."""
656656
if callable(attribute):
657-
attribute = self._render_template(
658-
call_with_asked_args(attribute, self.process_args)
659-
)
657+
attribute = call_with_asked_args(attribute, self.process_args)
660658
return self._render_template(attribute)
661659

662660
@web.authenticated

tests/resources/jupyter_server_config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def cats_only(response, path):
4242
response.code = 403
4343
response.body = b"dogs not allowed"
4444

45+
def my_env():
46+
return {
47+
"MYVAR": "String with escaped {{var}}"
48+
}
4549

4650
c.ServerProxy.servers = {
4751
"python-http": {
@@ -65,6 +69,10 @@ def cats_only(response, path):
6569
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
6670
"mappath": mappathf,
6771
},
72+
"python-http-callable-env": {
73+
"command": [sys.executable, "./tests/resources/httpinfo.py", "--port={port}"],
74+
"environment": my_env,
75+
},
6876
"python-websocket": {
6977
"command": [sys.executable, "./tests/resources/websocket.py", "--port={port}"],
7078
"request_headers_override": {

tests/test_proxies.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,9 @@ def test_bad_server_proxy_url(
408408
if status >= 400:
409409
# request should not have been proxied
410410
assert "X-ProxyContextPath" not in r.headers
411+
412+
413+
def test_callable_environment_formatting(a_server_port_and_token: Tuple[int, str]) -> None:
414+
PORT, TOKEN = a_server_port_and_token
415+
r = request_get(PORT, "/python-http-callable-env/test", TOKEN)
416+
assert r.code == 200

0 commit comments

Comments
 (0)