Commits

Matthew Schinckel committed 06e08b0

Fix an issue where invalid strings still passed parsing.

  • Participants
  • Parent commits 14c616d

Comments (0)

Files changed (2)

File timedelta/helpers.py

         raise TypeError("'%s' is not a valid time interval" % string)
     # This is the format we get from sometimes Postgres, sqlite,
     # and from serialization
-    d = re.match(r'((?P<days>\d+) days?,? )?(?P<hours>\d+):'
-                 r'(?P<minutes>\d+)(:(?P<seconds>\d+(\.\d+)?))?',
+    d = re.match(r'^((?P<days>\d+) days?,? )?(?P<hours>\d+):'
+                 r'(?P<minutes>\d+)(:(?P<seconds>\d+(\.\d+)?))?$',
                  unicode(string))
     if d: 
         d = d.groupdict(0)

File timedelta/tests.py

         datetime.timedelta(1, 31362, 342000)
         >>> t.clean('3 days, 8:42:42.342161')
         datetime.timedelta(3, 31362, 342161)
+        >>> t.clean('3 days, 8:42:42.3.42161')
+        Traceback (most recent call last):
+        ValidationError: [u'Enter a valid time span: e.g. "3 days, 4 hours, 2 minutes"']
         >>> t.clean('5 day, 8:42:42')
         datetime.timedelta(5, 31362)
         >>> t.clean('1 days')