[azure-core] Fix format_url dropping trailing slash when URL template is query-string only#45366
[azure-core] Fix format_url dropping trailing slash when URL template is query-string only#45366
format_url dropping trailing slash when URL template is query-string only#45366Conversation
…string only Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
format_url dropping trailing slash when URL template is query-string only
|
/azp run python - tables - ci |
|
No pipelines are associated with this pull request. |
|
/azp run python - tables - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run python - storage - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@copilot our tables tests are failing with this change |
…only stubs Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
Fixed in commit The key logic: # Only strip trailing slash from base when stub has a path component.
# For query-string-only stubs (e.g. "?key=val"), preserve any trailing
# slash so it appears before the query string in the final URL.
if url.split("?", 1)[0]:
base = base.rstrip("/")
url = _urljoin(base, url)Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Pull request overview
Fixes PipelineClientBase.format_url so a base URL’s trailing slash is preserved when the provided URL template is query-string-only (e.g. ?key=value), preventing incorrect path truncation before the ?.
Changes:
- Removed unconditional trailing-slash stripping from base URL formatting in
format_url. - Added a regression test covering query-string-only templates with a trailing-slash base URL.
- Documented the fix in the unreleased changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| sdk/core/azure-core/azure/core/pipeline/transport/_base.py | Stops stripping trailing slash from the formatted base URL, enabling correct join behavior for query-only templates. |
| sdk/core/azure-core/tests/test_pipeline.py | Adds a regression test to ensure trailing slashes are preserved for query-only URL templates. |
| sdk/core/azure-core/CHANGELOG.md | Notes the bug fix in the unreleased “Bugs Fixed” section. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

When
format_urlis called with a query-string-only template (e.g.?key=value) and the base URL (resolved frompath_format_arguments) has a trailing slash, the trailing slash is incorrectly stripped.Changes
_base.py: Removed the unconditional.rstrip("/")from the base URL computation informat_url. This was always redundant for path stubs —_urljoinalready strips the trailing slash from the base path inside itsif stub_url_path:branch when actually joining path segments. For query-string-only stubs wherestub_url_pathis empty,_urljoinleaves the base path untouched, so the trailing slash is now correctly preserved before the?.test_pipeline.py: Added test covering the exact scenario from the issue.CHANGELOG.md: Updated unreleased section.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.