Skip to content

Allow url encoded queries #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

### Fixed

* Allow url encoded values for `query` in GET requests ([#504](https://github.com/stac-utils/stac-fastapi/pull/504))

## [2.4.3]

### Added
Expand All @@ -22,7 +24,6 @@

### Fixed


## [2.4.2]

### Added
Expand Down
4 changes: 2 additions & 2 deletions stac_fastapi/pgstac/stac_fastapi/pgstac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
from datetime import datetime
from typing import Any, Dict, List, Optional, Union
from urllib.parse import urljoin
from urllib.parse import unquote_plus, urljoin

import attr
import orjson
Expand Down Expand Up @@ -372,7 +372,7 @@ async def get_search(
"bbox": bbox,
"limit": limit,
"token": token,
"query": orjson.loads(query) if query else query,
"query": orjson.loads(unquote_plus(query)) if query else query,
}

if filter:
Expand Down
8 changes: 8 additions & 0 deletions stac_fastapi/pgstac/tests/api/test_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import datetime, timedelta
from urllib.parse import quote_plus

import orjson
import pytest

STAC_CORE_ROUTES = [
Expand Down Expand Up @@ -102,6 +104,12 @@ async def test_app_query_extension(load_test_data, app_client, load_test_collect
resp_json = resp.json()
assert len(resp_json["features"]) == 1

params["query"] = quote_plus(orjson.dumps(params["query"]))
resp = await app_client.get("/search", params=params)
assert resp.status_code == 200
resp_json = resp.json()
assert len(resp_json["features"]) == 1


async def test_app_query_extension_limit_1(
load_test_data, app_client, load_test_collection
Expand Down
4 changes: 2 additions & 2 deletions stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import operator
from datetime import datetime
from typing import List, Optional, Set, Type, Union
from urllib.parse import urlencode, urljoin
from urllib.parse import unquote_plus, urlencode, urljoin

import attr
import geoalchemy2 as ga
Expand Down Expand Up @@ -243,7 +243,7 @@ def get_search(
"bbox": bbox,
"limit": limit,
"token": token,
"query": json.loads(query) if query else query,
"query": json.loads(unquote_plus(query)) if query else query,
}

if datetime:
Expand Down
9 changes: 9 additions & 0 deletions stac_fastapi/sqlalchemy/tests/api/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from datetime import datetime, timedelta
from urllib.parse import quote_plus

import orjson

from ..conftest import MockStarletteRequest

Expand Down Expand Up @@ -150,6 +153,12 @@ def test_app_query_extension_gt(load_test_data, app_client, postgres_transaction
resp_json = resp.json()
assert len(resp_json["features"]) == 0

params["query"] = quote_plus(orjson.dumps(params["query"]))
resp = app_client.get("/search", params=params)
assert resp.status_code == 200
resp_json = resp.json()
assert len(resp_json["features"]) == 0


def test_app_query_extension_gte(load_test_data, app_client, postgres_transactions):
test_item = load_test_data("test_item.json")
Expand Down