Skip to content
Snippets Groups Projects
Commit 2a43219d authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

FIX: Respect context-root and make links platform independent

parent 718b3095
No related branches found
No related tags found
2 merge requests!181Release 0.9.0,!179F fix url formatting
Pipeline #54519 passed
...@@ -25,9 +25,9 @@ ...@@ -25,9 +25,9 @@
# Some utility functions, e.g. for extending pylib. # Some utility functions, e.g. for extending pylib.
import os
import sys import sys
from posixpath import join as posixjoin
from typing import Optional from typing import Optional
from urllib.parse import urljoin from urllib.parse import urljoin
...@@ -81,4 +81,9 @@ def get_shared_resource_link(host_url, filename): ...@@ -81,4 +81,9 @@ def get_shared_resource_link(host_url, filename):
""" """
return urljoin(host_url, os.path.join("/Shared/", filename)) if not host_url.endswith('/'):
# Fill with trailing '/' s. that urljoin doesn't remove the context root.
host_url += '/'
# Use posixjoin to always have '/' in links, even when running on
# Windows systems.
return urljoin(host_url, posixjoin("Shared/", filename))
...@@ -76,3 +76,7 @@ def test_shared_resource_link(): ...@@ -76,3 +76,7 @@ def test_shared_resource_link():
"https://example.com", "file.txt") == "https://example.com/Shared/file.txt" "https://example.com", "file.txt") == "https://example.com/Shared/file.txt"
assert get_shared_resource_link( assert get_shared_resource_link(
"https://example.com", "path/to/file.txt") == "https://example.com/Shared/path/to/file.txt" "https://example.com", "path/to/file.txt") == "https://example.com/Shared/path/to/file.txt"
assert get_shared_resource_link(
"https://example.com/context-root", "path/to/file.txt") == "https://example.com/context-root/Shared/path/to/file.txt"
assert get_shared_resource_link(
"https://example.com/context-root/", "path/to/file.txt") == "https://example.com/context-root/Shared/path/to/file.txt"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment