Skip to content

Commit 7a90819

Browse files
Ensure client self hrefs don't end in '/' (#373)
* fix: ensure client self hrefs don't end in '/' * chore: update changelog * fix: remove multiple `/` characters from url Co-authored-by: Tom Augspurger <tom.w.augspurger@gmail.com> Co-authored-by: Tom Augspurger <tom.w.augspurger@gmail.com>
1 parent 2b00b1e commit 7a90819

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1818
### Fixed
1919

2020
- Some mishandled cases for datetime intervals [#363](https://github.com/stac-utils/pystac-client/pull/363)
21+
- Collection requests when the Client's url ends in a '/' [#373](https://github.com/stac-utils/pystac-client/pull/373)
2122
- Parse datetimes more strictly [#364](https://github.com/stac-utils/pystac-client/pull/364)
2223

2324
### Removed

Diff for: pystac_client/client.py

+1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def open(
149149
Return:
150150
catalog : A :class:`Client` instance for this Catalog/API
151151
"""
152+
url = url.rstrip("/")
152153
client: Client = cls.from_file(
153154
url,
154155
headers=headers,

Diff for: tests/test_client.py

+18
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ def test_get_collections_with_conformance(self, requests_mock: Mocker) -> None:
128128
assert len(history) == 2
129129
assert history[1].url == collections_link.href
130130

131+
def test_get_collections_single_slash(self, requests_mock: Mocker) -> None:
132+
pc_root_text = read_data_file("planetary-computer-root.json")
133+
root_url = "http://pystac-client.test/"
134+
requests_mock.get(root_url, status_code=200, text=pc_root_text)
135+
api = Client.open(root_url)
136+
pc_collection_dict = read_data_file(
137+
"planetary-computer-aster-l1t-collection.json", parse_json=True
138+
)
139+
requests_mock.get(
140+
f"{root_url}collections", # note the lack of the slash
141+
status_code=200,
142+
json={"collections": [pc_collection_dict], "links": []},
143+
)
144+
_ = next(api.get_collections())
145+
history = requests_mock.request_history
146+
assert len(history) == 2
147+
assert history[1].url == f"{root_url}collections"
148+
131149
def test_custom_request_parameters(self, requests_mock: Mocker) -> None:
132150
pc_root_text = read_data_file("planetary-computer-root.json")
133151
pc_collection_dict = read_data_file(

0 commit comments

Comments
 (0)