Skip to content

Commit

Permalink
Parse datetimes more strictly (#364)
Browse files Browse the repository at this point in the history
* fix: parse datetimes more strictly

The whole string must now match the regex.

* chore: update changelog
  • Loading branch information
gadomski authored Dec 12, 2022
1 parent 0390adf commit 2b00b1e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pystac_client/item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
from pystac_client import client as _client

DATETIME_REGEX = re.compile(
r"(?P<year>\d{4})(-(?P<month>\d{2})(-(?P<day>\d{2})"
r"^(?P<year>\d{4})(-(?P<month>\d{2})(-(?P<day>\d{2})"
r"(?P<remainder>([Tt])\d{2}:\d{2}:\d{2}(\.\d+)?"
r"(?P<tz_info>Z|([-+])(\d{2}):(\d{2}))?)?)?)?"
r"(?P<tz_info>[Zz]|([-+])(\d{2}):(\d{2}))?)?)?)?$"
)


Expand Down
4 changes: 4 additions & 0 deletions tests/test_item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 2b00b1e

Please sign in to comment.