Skip to content

fix: keep query and fragment in relative URL hrefs - #1868

Merged
jsignell merged 1 commit into
stac-utils:mainfrom
Keval-P:relative-href-query
Dec 1, 2026
Merged

jsignell merged 1 commit into
stac-utils:mainfrom
Keval-P:relative-href-query

Conversation

@Keval-P

@Keval-P Keval-P commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Related Issue(s):

  • None that I could find

Description:

make_relative_href drops the query string and fragment of the source href when both hrefs are URLs with the same scheme and host:

>>> make_relative_href("https://example.com/stac/items/data/i.tif?sig=abc", "https://example.com/stac/items/i.json")
'./data/i.tif'

So an item whose asset href is a signed URL loses the token on make_asset_hrefs_relative() (or when saving a self-contained catalog), and make_asset_hrefs_absolute() can't bring it back. The other direction already keeps it: _make_absolute_href_url passes the source params, query and fragment through urlunparse. This does the same in _make_relative_href_url, so the example above now gives ./data/i.tif?sig=abc and round-trips back to the original href.

Local file paths are not touched.

Added two cases (query and fragment) to the test_make_relative_href parametrization; both fail on main and pass with the change.

PR Checklist:

  • Pre-commit hooks pass (run pre-commit run --all-files)
  • Tests pass (run pytest): 1564 passed, 18 skipped locally
  • Documentation has been updated to reflect changes, if applicable
  • This PR maintains or improves overall codebase code coverage
  • This PR's title is formatted per conventional commits

make_relative_href dropped the query string and fragment of the source when
both hrefs were URLs on the same host, so a signed asset href such as
.../data.tif?sig=abc lost its token after make_asset_hrefs_relative() and
could not be recovered by make_asset_hrefs_absolute().

_make_absolute_href_url already carries the source query and fragment through;
do the same in _make_relative_href_url.
@jsignell
jsignell self-requested a review December 1, 2026 15:38

@jsignell jsignell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks @Keval-P

@jsignell
jsignell enabled auto-merge December 1, 2026 15:45
@jsignell
jsignell disabled auto-merge December 1, 2026 16:49
@jsignell
jsignell merged commit deb1a68 into stac-utils:main Dec 1, 2026
16 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants