Skip to content

Commit fcaf7bc

Browse files
Copilotl0lawrence
andcommitted
Fix format_url to preserve trailing slash when url_template is query-string only
Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
1 parent 7fa57e5 commit fcaf7bc

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

sdk/core/azure-core/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Bugs Fixed
1010

11+
- Fixed `PipelineClient.format_url` to preserve trailing slash in the base URL when the URL template is a query-string only (e.g. `?key=value`). #40426
12+
1113
### Other Changes
1214

1315
## 1.38.2 (2026-02-18)

sdk/core/azure-core/azure/core/pipeline/transport/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ def format_url(self, url_template: str, **kwargs: Any) -> str:
663663
parsed = urlparse(url)
664664
if not parsed.scheme or not parsed.netloc:
665665
try:
666-
base = self._base_url.format(**kwargs).rstrip("/")
666+
base = self._base_url.format(**kwargs)
667667
except KeyError as key:
668668
err_msg = "The value provided for the url part {} was incorrect, and resulted in an invalid url"
669669
raise ValueError(err_msg.format(key.args[0])) from key

sdk/core/azure-core/tests/test_pipeline.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ def test_format_url_query_strings():
225225
assert formatted == "https://foo.core.windows.net/Tables?a=X&c=Y"
226226

227227

228+
def test_format_url_trailing_slash_preserved_with_query_only():
229+
# Test that trailing slash in base URL is preserved when url_template is query-string only
230+
# https://github.com/Azure/azure-sdk-for-python/issues/XXXXX
231+
client = PipelineClientBase("{url}")
232+
formatted = client.format_url("?versionid=2026-02-25", url="https://storage.blob.core.windows.net/sample//a/a/")
233+
assert formatted == "https://storage.blob.core.windows.net/sample//a/a/?versionid=2026-02-25"
234+
235+
228236
def test_format_url_from_http_request():
229237
client = PipelineClientBase("https://foo.core.windows.net")
230238

0 commit comments

Comments
 (0)