From 2dec77fc76afd660e57c9eabe76f9ea47b9353fc Mon Sep 17 00:00:00 2001 From: Frank Dana Date: Sat, 8 Jun 2024 10:54:06 -0400 Subject: [PATCH 1/3] Fix is_iso_date pattern Signed-off-by: FeRD (Frank Dana) --- src/saneyaml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 1f95f74d882cb977dca1730c779d18cf71c96f8a Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Sat, 8 Jun 2024 12:50:39 -0400 Subject: [PATCH 2/3] Add tests for is_iso_date Signed-off-by: FeRD (Frank Dana) --- tests/test_saneyaml.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/test_saneyaml.py b/tests/test_saneyaml.py index bd296a7..c174494 100644 --- a/tests/test_saneyaml.py +++ b/tests/test_saneyaml.py @@ -137,6 +137,19 @@ 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') + safe_chars = re.compile(r'[\W_]', re.MULTILINE) From 3d90ec9d50b000904d1613f446a4d6ab0d425a17 Mon Sep 17 00:00:00 2001 From: Philippe Ombredanne Date: Sat, 8 Jun 2024 19:09:21 +0200 Subject: [PATCH 3/3] Add weird is_iso_date tests #14 These are non-valid ISO dates but we do not validate fully just a surface validation using a regex. This captures the weird cases we accept. Reference: https://github.com/nexB/saneyaml/issues/14 Signed-off-by: Philippe Ombredanne Co-authored-by: Frank Dana Signed-off-by: FeRD (Frank Dana) --- tests/test_saneyaml.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_saneyaml.py b/tests/test_saneyaml.py index c174494..d0e704c 100644 --- a/tests/test_saneyaml.py +++ b/tests/test_saneyaml.py @@ -149,6 +149,9 @@ def test_is_iso_date(self): 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)