diff --git a/jellyfin_apiclient_python/api.py b/jellyfin_apiclient_python/api.py index 1328b56..64f717a 100644 --- a/jellyfin_apiclient_python/api.py +++ b/jellyfin_apiclient_python/api.py @@ -13,7 +13,8 @@ def jellyfin_url(client, handler): - return "%s/%s" % (client.config.data['auth.server'], handler) + base_url = client.config.data['auth.server'].rstrip('/') + return f"{base_url}/{handler.lstrip('/')}" def basic_info(): diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..a741b3b --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,13 @@ +from jellyfin_apiclient_python.api import jellyfin_url +from unittest.mock import Mock + +def test_jellyfin_url_handles_trailing_slash(): + mock_client = Mock() + mock_client.config.data = {'auth.server': 'https://example.com/'} + handler = "Items/1234" + url = jellyfin_url(mock_client, handler) + assert url == "https://example.com/Items/1234" + + mock_client.config.data = {'auth.server': 'https://example.com'} + url = jellyfin_url(mock_client, handler) + assert url == "https://example.com/Items/1234"