Skip to content

Commit

Permalink
Always quote params for modern ERDDAP servers
Browse files Browse the repository at this point in the history
  • Loading branch information
ocefpaf committed Sep 18, 2024
1 parent e5ad558 commit dae2469
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion erddapy/core/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
OptionalList = list[str] | tuple[str] | None


def quote_url(url: str) -> str:
"""Quote URL args for modern ERDDAP servers."""
# We should always quote for queries.
if "?" in url and not "searchFor":
base, unquoted = url.split("?")
url = f"{base}?{parse.quote_plus(unquoted)}"
return url


def _sort_url(url: str) -> str:
"""Return a URL with sorted variables and constraints for hashing."""
parts = parse.urlparse(url)
Expand All @@ -48,7 +57,12 @@ def _sort_url(url: str) -> str:
def _urlopen(url: str, auth: tuple | None = None, **kwargs: dict) -> BinaryIO:
if "timeout" not in kwargs:
kwargs["timeout"] = 60
response = httpx.get(url, follow_redirects=True, auth=auth, **kwargs)
response = httpx.get(
quote_url(url),
follow_redirects=True,
auth=auth,
**kwargs,
)
try:
response.raise_for_status()
except httpx.HTTPError as err:
Expand Down

0 comments on commit dae2469

Please sign in to comment.