diff --git a/jupyter_server/gateway/managers.py b/jupyter_server/gateway/managers.py index 7b19e874e5..cc4c2de5c8 100644 --- a/jupyter_server/gateway/managers.py +++ b/jupyter_server/gateway/managers.py @@ -218,13 +218,16 @@ def _replace_path_kernelspec_resources(self, kernel_specs): for resource_name in resources: original_path = resources[resource_name] split_eg_base_url = str.rsplit(original_path, sep="/kernelspecs/", maxsplit=1) - new_path = url_path_join(self.parent.base_url, "kernelspecs", split_eg_base_url[1]) - kernel_specs["kernelspecs"][kernel_name]["resources"][resource_name] = new_path - if original_path != new_path: - self.log.debug( - f"Replaced original kernel resource path {original_path} with new " - f"path {kernel_specs['kernelspecs'][kernel_name]['resources'][resource_name]}" + if len(split_eg_base_url) > 1: + new_path = url_path_join( + self.parent.base_url, "kernelspecs", split_eg_base_url[1] ) + kernel_specs["kernelspecs"][kernel_name]["resources"][resource_name] = new_path + if original_path != new_path: + self.log.debug( + f"Replaced original kernel resource path {original_path} with new " + f"path {kernel_specs['kernelspecs'][kernel_name]['resources'][resource_name]}" + ) return kernel_specs def _get_kernelspecs_endpoint_url(self, kernel_name=None): diff --git a/tests/test_gateway.py b/tests/test_gateway.py index 4298d3f3e1..6d980601c0 100644 --- a/tests/test_gateway.py +++ b/tests/test_gateway.py @@ -41,7 +41,10 @@ def generate_kernelspec(name): kernelspec_stanza = { "name": name, "spec": spec_stanza, - "resources": {"logo-64x64": f"f/kernelspecs/{name}/logo-64x64.png"}, + "resources": { + "logo-64x64": f"f/kernelspecs/{name}/logo-64x64.png", + "url": "https://example.com/example-url", + }, } return kernelspec_stanza