Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make absolute hrefs from urls #697

Merged
merged 2 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### Fixed

- Quickstart tutorial is now up-to-date with all package changes ([#674](https://github.com/stac-utils/pystac/pull/674))
- Creating absolute URLs from absolute URLs ([#697](https://github.com/stac-utils/pystac/pull/697)])

### Deprecated

Expand Down
9 changes: 6 additions & 3 deletions pystac/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,13 @@ def make_absolute_href(
parsed_start = safe_urlparse(start_href)
parsed_source = safe_urlparse(source_href)

if JoinType.from_parsed_uri(parsed_start) == JoinType.PATH:
return _make_absolute_href_path(parsed_source, parsed_start, start_is_dir)
else:
if (
JoinType.from_parsed_uri(parsed_source) == JoinType.URL
or JoinType.from_parsed_uri(parsed_start) == JoinType.URL
):
return _make_absolute_href_url(parsed_source, parsed_start, start_is_dir)
else:
return _make_absolute_href_path(parsed_source, parsed_start, start_is_dir)


def is_absolute_href(href: str) -> bool:
Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def test_make_absolute_href(self) -> None:
"https://stacspec.org/a/b/c/catalog.json",
"https://stacspec.org/a/b/item.json",
),
("http://localhost:8000", None, "http://localhost:8000"),
]

for source_href, start_href, expected in test_cases:
Expand Down