diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index 2fb610e6bb64..740706311091 100644 --- a/sdk/core/azure-core/CHANGELOG.md +++ b/sdk/core/azure-core/CHANGELOG.md @@ -8,6 +8,8 @@ ### Bugs Fixed +- Fixed `PipelineClient.format_url` to preserve trailing slash in the base URL when the URL template is query-string-only (e.g., `?key=value`). #45365 + ### Other Changes ## 1.38.2 (2026-02-18) diff --git a/sdk/core/azure-core/azure/core/pipeline/transport/_base.py b/sdk/core/azure-core/azure/core/pipeline/transport/_base.py index 6e33aa77df73..91b43e9bb70f 100644 --- a/sdk/core/azure-core/azure/core/pipeline/transport/_base.py +++ b/sdk/core/azure-core/azure/core/pipeline/transport/_base.py @@ -663,7 +663,7 @@ def format_url(self, url_template: str, **kwargs: Any) -> str: parsed = urlparse(url) if not parsed.scheme or not parsed.netloc: try: - base = self._base_url.format(**kwargs).rstrip("/") + base = self._base_url.format(**kwargs) except KeyError as key: err_msg = "The value provided for the url part {} was incorrect, and resulted in an invalid url" raise ValueError(err_msg.format(key.args[0])) from key diff --git a/sdk/core/azure-core/tests/test_pipeline.py b/sdk/core/azure-core/tests/test_pipeline.py index 5612b8b2a45f..af6ca1a1a0ea 100644 --- a/sdk/core/azure-core/tests/test_pipeline.py +++ b/sdk/core/azure-core/tests/test_pipeline.py @@ -225,6 +225,14 @@ def test_format_url_query_strings(): assert formatted == "https://foo.core.windows.net/Tables?a=X&c=Y" +def test_format_url_trailing_slash_preserved_with_query_only(): + # Test that trailing slash in base URL is preserved when url_template is query-string only + # https://github.com/Azure/azure-sdk-for-python/issues/45365 + client = PipelineClientBase("{url}") + formatted = client.format_url("?versionid=2026-02-25", url="https://storage.blob.core.windows.net/sample//a/a/") + assert formatted == "https://storage.blob.core.windows.net/sample//a/a/?versionid=2026-02-25" + + def test_format_url_from_http_request(): client = PipelineClientBase("https://foo.core.windows.net")