diff --git a/src/saneyaml.py b/src/saneyaml.py index eb0c19f..dcc5903 100644 --- a/src/saneyaml.py +++ b/src/saneyaml.py @@ -327,7 +327,7 @@ def is_float(s): # Return True if s is an iso date such as `2019-12-12` -is_iso_date = re.compile(r'19|20[0-9]{2}-[0-1][0-9]-[0-3]?[1-9]').match +is_iso_date = re.compile(r'(19|20)[0-9]{2}-[0-1][0-9]-[0-3][0-9]').match SaneDumper.add_representer(int, SaneDumper.string_dumper) SaneDumper.add_representer(dict, SaneDumper.ordered_dumper) diff --git a/tests/test_saneyaml.py b/tests/test_saneyaml.py index bd296a7..d0e704c 100644 --- a/tests/test_saneyaml.py +++ b/tests/test_saneyaml.py @@ -137,6 +137,22 @@ def test_load_ignore_aliases(self): ]) assert expected == result + def test_is_iso_date(self): + assert saneyaml.is_iso_date('1994-01-01') + assert saneyaml.is_iso_date('2004-01-01') + assert not saneyaml.is_iso_date('1800-01-01') + assert not saneyaml.is_iso_date('2100-01-01') + assert saneyaml.is_iso_date('2004-01-30') + assert not saneyaml.is_iso_date('2004-01-40') + assert not saneyaml.is_iso_date('2004-01-4') + assert not saneyaml.is_iso_date('2004-01-3a') + assert not saneyaml.is_iso_date('1994-01-1') + assert not saneyaml.is_iso_date('1994-1-1') + assert not saneyaml.is_iso_date('193') + # Hey, nothing's perfect + assert saneyaml.is_iso_date('2003-02-29') + assert saneyaml.is_iso_date('2004-01-35') + safe_chars = re.compile(r'[\W_]', re.MULTILINE)