From 258ee48c0106a136efb3083c2145925c38f93328 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Tue, 4 Jan 2022 07:15:46 -0700 Subject: [PATCH 1/2] fix: make absolute hrefs from urls The very basic case of `make_absolute_href(href, None, None)` was broken if `href` was a url. This fixes that breakage with a test case to demonstrate. Discovered while investigating https://github.com/stac-utils/pystac-client/issues/113. --- pystac/utils.py | 9 ++++++--- tests/test_utils.py | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pystac/utils.py b/pystac/utils.py index 8232e7a0a..f79493db8 100644 --- a/pystac/utils.py +++ b/pystac/utils.py @@ -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: diff --git a/tests/test_utils.py b/tests/test_utils.py index 4f6e1d849..453dc6fcd 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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: From 3092bdcb53f930687ea277da86535d9f993f6b84 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Tue, 4 Jan 2022 07:21:19 -0700 Subject: [PATCH 2/2] chore: update changelog for #697 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 181c34020..870f93a7a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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