From 3dd6dfdf9a2a614970d96d15c256354ad047a683 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Mon, 28 Nov 2022 15:17:14 -0700 Subject: [PATCH 1/2] fix: parse datetimes more strictly The whole string must now match the regex. --- pystac_client/item_search.py | 4 ++-- tests/test_item_search.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pystac_client/item_search.py b/pystac_client/item_search.py index ba1295d2..a229aecc 100644 --- a/pystac_client/item_search.py +++ b/pystac_client/item_search.py @@ -34,9 +34,9 @@ from pystac_client import client as _client DATETIME_REGEX = re.compile( - r"(?P\d{4})(-(?P\d{2})(-(?P\d{2})" + r"^(?P\d{4})(-(?P\d{2})(-(?P\d{2})" r"(?P([Tt])\d{2}:\d{2}:\d{2}(\.\d+)?" - r"(?PZ|([-+])(\d{2}):(\d{2}))?)?)?)?" + r"(?P[Zz]|([-+])(\d{2}):(\d{2}))?)?)?)?$" ) diff --git a/tests/test_item_search.py b/tests/test_item_search.py index 718742d0..bdfc76f4 100644 --- a/tests/test_item_search.py +++ b/tests/test_item_search.py @@ -276,6 +276,10 @@ def test_datetime_list_of_one_none(self) -> None: with pytest.raises(Exception): ItemSearch(url=SEARCH_URL, datetime=[None]) + def test_poorly_formed_datetimes(self) -> None: + with pytest.raises(Exception): + ItemSearch(url=SEARCH_URL, datetime="2020-7/2020-8") + def test_single_collection_string(self) -> None: # Single ID string search = ItemSearch(url=SEARCH_URL, collections="naip") From c99c2007fe83f9d03d6dfb0fbe50d5dbf7191ac0 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Mon, 28 Nov 2022 15:19:14 -0700 Subject: [PATCH 2/2] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b6f6362..b4de2a00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Some mishandled cases for datetime intervals [#363](https://github.com/stac-utils/pystac-client/pull/363) +- Parse datetimes more strictly [#364](https://github.com/stac-utils/pystac-client/pull/364) ### Removed