diff --git a/CHANGELOG.md b/CHANGELOG.md index eb24c725..cfd88d5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,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 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")