diff --git a/src/writer/auth.py b/src/writer/auth.py index 1c8144224..646208543 100644 --- a/src/writer/auth.py +++ b/src/writer/auth.py @@ -339,14 +339,17 @@ def urljoin(*args): >>> "app1/edit" >>> urljoin("/app1/", "/edit") - >>> "app1/edit" + >>> "/app1/edit" """ + root_part = args[0] + root_part_is_root_path = root_part.startswith('/') and len(root_part) > 1 + url_strip_parts = [] for part in args: if part: url_strip_parts.append(urlstrip(part)) - return '/'.join(url_strip_parts) + return '/'.join(url_strip_parts) if root_part_is_root_path is False else '/' + '/'.join(url_strip_parts) def urlstrip(url_path: str): """ diff --git a/tests/backend/test_auth.py b/tests/backend/test_auth.py index fa944ebdf..443ef11c7 100644 --- a/tests/backend/test_auth.py +++ b/tests/backend/test_auth.py @@ -43,7 +43,8 @@ def test_basicauth_authentication_module_disabled_when_server_setup_hook_is_disa ("http://localhost", "/"), ("http://localhost/", "/"), ("http://localhost/any", "/any"), - ("http://localhost/any/", "/any/") + ("http://localhost/any/", "/any/"), + ("/any/yolo", "/any/yolo") ]) def test_url_path_scenarios(self, path: str, expected_path: str): assert auth.urlpath(path) == expected_path @@ -63,6 +64,8 @@ def test_url_split_scenarios(self, path: str, expected_path: str): @pytest.mark.parametrize("path1,path2,expected_path", [ ("/", "any", "/any"), ("", "any", "any"), + ("/yolo", "any", "/yolo/any"), + ("/yolo", "/any", "/yolo/any"), ("http://localhost", "any", "http://localhost/any"), ("http://localhost/", "/any", "http://localhost/any"), ("http://localhost/yolo", "/any", "http://localhost/yolo/any"),