From 7ec32b607fb57f7d2bde44d079d6461455c459e8 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Fri, 31 May 2013 11:53:18 -0400 Subject: [PATCH] - Fix bug introduced by supporting spec-mandated truncations of ISO-8601 timezones. A TypeError would be raised instead of Invalid. See https://github.com/Pylons/colander/issues/111. Ref issue #111. --- CHANGES.txt | 7 +++++++ colander/iso8601.py | 4 ++++ colander/tests/test_colander.py | 6 ++++++ colander/tests/test_iso8601.py | 4 ++++ 4 files changed, 21 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 1268241..3a0e5bf 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,10 @@ +Next release +------------ + +- Fix bug introduced by supporting spec-mandated truncations of ISO-8601 + timezones. A TypeError would be raised instead of Invalid. See + https://github.com/Pylons/colander/issues/111. + 1.0a4 (2013-05-21) ------------------ diff --git a/colander/iso8601.py b/colander/iso8601.py index d225bd2..cd72f51 100644 --- a/colander/iso8601.py +++ b/colander/iso8601.py @@ -129,6 +129,10 @@ def parse_date(datestring, default_timezone=UTC): raise ParseError("Unable to parse date string %r" % datestring) groups = m.groupdict() tz = parse_timezone(groups["timezone"], default_timezone=default_timezone) + if (groups['year'] is None or + groups['month'] is None or + groups['day'] is None): + raise ParseError('Unable to parse date string %r' % datestring) if groups["hour"] is None: groups["hour"] = 0 if groups["minute"] is None: diff --git a/colander/tests/test_colander.py b/colander/tests/test_colander.py index da9e309..d5f123a 100644 --- a/colander/tests/test_colander.py +++ b/colander/tests/test_colander.py @@ -1954,6 +1954,12 @@ class TestDateTime(unittest.TestCase): e = invalid_exc(typ.deserialize, node, 'garbage') self.assertTrue('Invalid' in e.msg) + def test_deserialize_slashes_invalid(self): + node = DummySchemaNode(None) + typ = self._makeOne() + e = invalid_exc(typ.deserialize, node, '2013/05/31') + self.assertTrue('Invalid' in e.msg) + def test_deserialize_null(self): import colander node = DummySchemaNode(None) diff --git a/colander/tests/test_iso8601.py b/colander/tests/test_iso8601.py index 18e7525..722c104 100644 --- a/colander/tests/test_iso8601.py +++ b/colander/tests/test_iso8601.py @@ -168,3 +168,7 @@ class Test_parse_date(unittest.TestCase): datetime.datetime(2007, 1, 25, 0, 0, 0, 0, tzinfo=UTC)) + def test_slash_separated_raises_ParseError(self): + from ..iso8601 import ParseError + self.assertRaises(ParseError, self._callFUT, "2007/01/25") +