Skip to content

Commit

Permalink
fix: don't double-encode
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Apr 3, 2023
1 parent 202be62 commit 2015e2a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
4 changes: 3 additions & 1 deletion pystac_client/item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ def _clean_params_for_get_request(self) -> Dict[str, Any]:
if "collections" in params:
params["collections"] = ",".join(params["collections"])
if "intersects" in params:
params["intersects"] = json.dumps(params["intersects"])
params["intersects"] = json.dumps(
params["intersects"], separators=(",", ":")
)
if "query" in params:
params["query"] = json.dumps(params["query"], separators=(",", ":"))
if "sortby" in params:
Expand Down
6 changes: 1 addition & 5 deletions pystac_client/stac_api_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
from copy import deepcopy
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterator, List, Optional, Union
from urllib.parse import quote_plus, urlparse
from urllib.parse import urlparse

import pystac
from pystac.link import Link
Expand Down Expand Up @@ -154,10 +154,6 @@ def request(
request = Request(method=method, url=href, headers=headers, json=parameters)
else:
params = deepcopy(parameters) or {}
if "intersects" in params:
params["intersects"] = json.dumps(params["intersects"])
if "query" in params:
params["query"] = quote_plus(params["query"])
request = Request(method="GET", url=href, headers=headers, params=params)
try:
modified = self._req_modifier(request) if self._req_modifier else None
Expand Down
3 changes: 1 addition & 2 deletions tests/test_item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,7 @@ def __geo_interface__(self) -> Dict[str, Any]:
def test_get_with_query(self, requests_mock: Mocker) -> None:
requests_mock.get(
(
f"{SEARCH_URL}?query=%257B%2522eo%253Acloud_cover"
"%2522%253A%257B%2522gte%2522%253A0%252C%2522lte%2522%253A10%257D%257D"
f"{SEARCH_URL}?query=%7B%22eo%3Acloud_cover%22%3A%7B%22gte%22%3A0%2C%22lte%22%3A10%7D%7D"
),
status_code=200,
json={"features": [{"foo": "bar"}], "links": []},
Expand Down

0 comments on commit 2015e2a

Please sign in to comment.