From 95f128de90aa0d5c438b4f6ce299ca8733c36b44 Mon Sep 17 00:00:00 2001 From: Josh Hamet Date: Sat, 26 Mar 2022 21:24:55 -0400 Subject: [PATCH 1/2] Regression in connection URL calcuation in ServerApp --- jupyter_server/serverapp.py | 4 +++- tests/test_serverapp.py | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/jupyter_server/serverapp.py b/jupyter_server/serverapp.py index acab9a7869..60e92c35bb 100644 --- a/jupyter_server/serverapp.py +++ b/jupyter_server/serverapp.py @@ -1976,8 +1976,10 @@ def _get_urlparts(self, path=None, include_token=False): scheme = "http+unix" netloc = urlencode_unix_socket_path(self.sock) else: + if not self.ip: + ip = "localhost" # Handle nonexplicit hostname. - if self.ip in ("", "0.0.0.0", "::"): + elif self.ip in ("0.0.0.0", "::"): ip = "%s" % socket.gethostname() else: ip = "[{}]".format(self.ip) if ":" in self.ip else self.ip diff --git a/tests/test_serverapp.py b/tests/test_serverapp.py index 3808eb4dc1..6092e0a248 100644 --- a/tests/test_serverapp.py +++ b/tests/test_serverapp.py @@ -229,6 +229,12 @@ def test_resolve_file_to_run_and_root_dir(prefix_path, root_dir, file_to_run, ex "http+unix://%2Ftmp%2Fjp-test.sock/test/?token=", "http+unix://%2Ftmp%2Fjp-test.sock/", ), + ( + {"ip": ""}, + "http://localhost:8888/?token=", + "http://127.0.0.1:8888/?token=", + "http://localhost:8888/", + ) ], ) def test_urls(config, public_url, local_url, connection_url): From 7e124c3166b38d9804fa344a54087e1ac650a7e9 Mon Sep 17 00:00:00 2001 From: FriendlyBot Date: Sun, 27 Mar 2022 09:43:13 +0000 Subject: [PATCH 2/2] Apply pre-commit --- tests/test_serverapp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_serverapp.py b/tests/test_serverapp.py index 6092e0a248..0cec767ebb 100644 --- a/tests/test_serverapp.py +++ b/tests/test_serverapp.py @@ -234,7 +234,7 @@ def test_resolve_file_to_run_and_root_dir(prefix_path, root_dir, file_to_run, ex "http://localhost:8888/?token=", "http://127.0.0.1:8888/?token=", "http://localhost:8888/", - ) + ), ], ) def test_urls(config, public_url, local_url, connection_url):