Skip to content

Commit c5ca8b1

Browse files
authored
Don't unquote in url_with_parameters (#530)
* fix: don't unquote in url_with_parameters * chore: update changelog
1 parent a759644 commit c5ca8b1

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2929
- Fix geometry instantiation in item-search-intersects.ipynb [#484](https://github.com/stac-utils/pystac-client/pull/484)
3030
- Three tests that were false positives due to out-of-date cassettes [#491](https://github.com/stac-utils/pystac-client/pull/491)
3131
- Max items checks when paging [#492](https://github.com/stac-utils/pystac-client/pull/492)
32+
- `ItemSearch.url_with_parameters` no longer unquotes the url [#530](https://github.com/stac-utils/pystac-client/pull/530)
3233

3334
### Removed
3435

pystac_client/item_search.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import re
3-
import urllib.parse
43
import warnings
54
from collections.abc import Iterable, Mapping
65
from copy import deepcopy
@@ -362,7 +361,7 @@ def url_with_parameters(self) -> str:
362361
url = request.prepare().url
363362
if url is None:
364363
raise ValueError("Could not construct a full url")
365-
return urllib.parse.unquote(url)
364+
return url
366365

367366
def _format_query(self, value: Optional[QueryLike]) -> Optional[Dict[str, Any]]:
368367
if value is None:

tests/test_item_search.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import operator
3+
import urllib.parse
34
from datetime import datetime, timedelta
45
from typing import Any, Dict, Iterator
56

@@ -99,7 +100,7 @@ def test_url_with_parameters(self) -> None:
99100
datetime="2020-02-01T00:00:00Z",
100101
bbox=[-104.5, 44.0, -104.0, 45.0],
101102
)
102-
assert "bbox=-104.5,44.0,-104.0,45.0" in search.url_with_parameters()
103+
assert "bbox=-104.5%2C44.0%2C-104.0%2C45.0" in search.url_with_parameters()
103104

104105
# Motivating example: https://github.com/stac-utils/pystac-client/issues/299
105106
search = ItemSearch(
@@ -110,7 +111,7 @@ def test_url_with_parameters(self) -> None:
110111
assert (
111112
search.url_with_parameters()
112113
== "https://planetarycomputer.microsoft.com/api/stac/v1/search?"
113-
"limit=100&bbox=88.214,27.927,88.302,28.034&collections=cop-dem-glo-30"
114+
"limit=100&bbox=88.214%2C27.927%2C88.302%2C28.034&collections=cop-dem-glo-30"
114115
)
115116

116117
def test_single_string_datetime(self) -> None:
@@ -803,3 +804,13 @@ def test_query_json_syntax() -> None:
803804
assert item_search._format_query(["eo:cloud_cover<=1", "eo:cloud_cover>0"]) == {
804805
"eo:cloud_cover": {"lte": "1", "gt": "0"}
805806
}
807+
808+
809+
def test_url_with_query_parameter() -> None:
810+
# https://github.com/stac-utils/pystac-client/issues/522
811+
search = ItemSearch(
812+
url="http://pystac-client.test", query={"eo:cloud_cover": {"lt": 42}}
813+
)
814+
url = urllib.parse.urlparse(search.url_with_parameters())
815+
query = urllib.parse.parse_qs(url.query)
816+
assert query["query"] == [r'{"eo:cloud_cover":{"lt":42}}']

0 commit comments

Comments
 (0)