Skip to content

fix: keep query, fragment and params in local path hrefs - #1869

Open
Keval-P wants to merge 1 commit into
stac-utils:mainfrom
Keval-P:fix-local-href-query-fragment
Open

Keval-P wants to merge 1 commit into
stac-utils:mainfrom
Keval-P:fix-local-href-query-fragment

Conversation

@Keval-P

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

Copy link
Copy Markdown
Contributor

Follow-up to #1868, this time for local paths.

make_absolute_href and make_relative_href run local paths through urlparse and then rebuild only the path, so whatever urlparse splits off is dropped when the source is a relative local path (or is made relative):

>>> make_absolute_href("./item.json?v=2", "/data/catalog.json")
'/data/item.json'
>>> make_absolute_href("./scene#1.tif", "/data/catalog.json")
'/data/scene'
>>> make_relative_href("/data/scene#1.tif", "/data/catalog.json")
'./scene'

An absolute local path keeps them (make_absolute_href("/data/item.json?v=2", ...) returns it unchanged), and so do URLs, so the result depended on whether the href happened to be relative. The # case is the worse one, since it silently points at a different file.

The fix re-attaches the params, query and fragment at the end of _make_absolute_href_path and _make_relative_href_path, the same way the URL helpers already do.

Testing: added cases to test_make_relative_href and test_make_absolute_href (query, # in a file name, ; in a file name, and a file:// start href). All 7 new cases fail on main and pass with the change. Full tests/ run: 1066 passed, 18 skipped. ruff, ruff format, mypy and codespell are clean on the touched files.

make_absolute_href and make_relative_href parse local paths with urlparse,
then rebuild only the path part. Anything urlparse splits off is lost when
the source is a relative (or made-relative) local path: "./item.json?v=2"
next to /a/b/c/catalog.json became /a/b/c/item.json, and a file named
"scene#1.tif" became "scene".

Absolute local paths and URLs already kept these parts. Re-attach the
params, query and fragment in _make_absolute_href_path and
_make_relative_href_path too.

This branch has not been deployed

No deployments
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.

1 participant