diff --git a/sdk/core/azure-core/CHANGELOG.md b/sdk/core/azure-core/CHANGELOG.md index c45caf490aa6..6ee9aee17722 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 avoid adding trailing slashes when the URL template contains only query parameters. + ### Other Changes ## 1.38.0 (2026-01-12) 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 a853bafda8e4..ec7d5bc5fa85 100644 --- a/sdk/core/azure-core/azure/core/pipeline/transport/_base.py +++ b/sdk/core/azure-core/azure/core/pipeline/transport/_base.py @@ -130,9 +130,10 @@ def _urljoin(base_url: str, stub_url: str) -> str: # Note that _replace is a public API named that way to avoid conflicts in namedtuple # https://docs.python.org/3/library/collections.html?highlight=namedtuple#collections.namedtuple - parsed_base_url = parsed_base_url._replace( - path=parsed_base_url.path.rstrip("/") + "/" + stub_url_path, - ) + if stub_url_path: + parsed_base_url = parsed_base_url._replace( + path=parsed_base_url.path.rstrip("/") + "/" + stub_url_path, + ) if stub_url_query: query_params = [stub_url_query] if parsed_base_url.query: diff --git a/sdk/core/azure-core/tests/test_basic_transport.py b/sdk/core/azure-core/tests/test_basic_transport.py index 24d3790f0590..2f8cfd70c8c1 100644 --- a/sdk/core/azure-core/tests/test_basic_transport.py +++ b/sdk/core/azure-core/tests/test_basic_transport.py @@ -128,7 +128,8 @@ def test_http_request_serialization(http_request): @pytest.mark.parametrize("http_request", HTTP_REQUESTS) def test_url_join(http_request): - assert _urljoin("devstoreaccount1", "") == "devstoreaccount1/" + assert _urljoin("devstoreaccount1", "?testdir") == "devstoreaccount1?testdir" + assert _urljoin("devstoreaccount1", "") == "devstoreaccount1" assert _urljoin("devstoreaccount1", "testdir/") == "devstoreaccount1/testdir/" assert _urljoin("devstoreaccount1/", "") == "devstoreaccount1/" assert _urljoin("devstoreaccount1/", "testdir/") == "devstoreaccount1/testdir/"