diff --git a/pendulum/__init__.py b/pendulum/__init__.py index bb1e0ca7..b19f87d5 100644 --- a/pendulum/__init__.py +++ b/pendulum/__init__.py @@ -251,7 +251,10 @@ def yesterday(tz="local"): # type: (Union[str, _Timezone]) -> DateTime def from_format( - string, fmt, tz=UTC, locale=None, # noqa + string, + fmt, + tz=UTC, + locale=None, # noqa ): # type: (str, str, Union[str, _Timezone], Optional[str]) -> DateTime """ Creates a DateTime instance from a specific format. diff --git a/pendulum/parsing/__init__.py b/pendulum/parsing/__init__.py index 1b5c8b91..57a5c010 100644 --- a/pendulum/parsing/__init__.py +++ b/pendulum/parsing/__init__.py @@ -212,7 +212,7 @@ def __init__(self, start=None, end=None, duration=None): def _parse_iso8601_interval(text): - if "/" not in text: + if text.count("/") != 1 or text.startswith("/") or text.endswith("/"): raise ParserError("Invalid interval") first, last = text.split("/") diff --git a/tests/datetime/test_from_format.py b/tests/datetime/test_from_format.py index 0949332c..398b68da 100644 --- a/tests/datetime/test_from_format.py +++ b/tests/datetime/test_from_format.py @@ -39,7 +39,8 @@ def test_from_format_with_timezone(): def test_from_format_with_square_bracket_in_timezone(): with pytest.raises(ValueError, match="^String does not match format"): pendulum.from_format( - "1975-05-21 22:32:11 Eu[rope/London", "YYYY-MM-DD HH:mm:ss z", + "1975-05-21 22:32:11 Eu[rope/London", + "YYYY-MM-DD HH:mm:ss z", ) diff --git a/tests/parsing/test_parsing.py b/tests/parsing/test_parsing.py index bcd7a53e..9387667a 100644 --- a/tests/parsing/test_parsing.py +++ b/tests/parsing/test_parsing.py @@ -670,6 +670,18 @@ def test_invalid(): with pytest.raises(ParserError): parse(text) + # Incomplete date + text = "/2020" + + with pytest.raises(ParserError): + parse(text) + + # Incomplete date + text = "2020/" + + with pytest.raises(ParserError): + parse(text) + def test_exif_edge_case(): text = "2016:12:26 15:45:28"