diff --git a/pendulum/formatting/formatter.py b/pendulum/formatting/formatter.py index 9c9b3404..9b64fcd6 100644 --- a/pendulum/formatting/formatter.py +++ b/pendulum/formatting/formatter.py @@ -33,7 +33,7 @@ "['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+" r"|[\u0600-\u06FF/]+(\s*?[\u0600-\u06FF]+){1,2}" ) -_MATCH_TIMEZONE = "[A-za-z0-9-+]+(/[A-Za-z0-9-+_]+)?" +_MATCH_TIMEZONE = "[A-Za-z0-9-+]+(/[A-Za-z0-9-+_]+)?" class Formatter: diff --git a/tests/datetime/test_from_format.py b/tests/datetime/test_from_format.py index 7f1d03ec..0949332c 100644 --- a/tests/datetime/test_from_format.py +++ b/tests/datetime/test_from_format.py @@ -36,6 +36,13 @@ def test_from_format_with_timezone(): assert "Europe/London" == d.timezone_name +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", + ) + + def test_from_format_with_escaped_elements(): d = pendulum.from_format("1975-05-21T22:32:11+00:00", "YYYY-MM-DD[T]HH:mm:ssZ") assert_datetime(d, 1975, 5, 21, 22, 32, 11)