]> granicus.if.org Git - python/commitdiff
Raise a ValueError when there is data that was not covered in the format string....
authorBrett Cannon <bcannon@gmail.com>
Mon, 28 Apr 2003 21:30:13 +0000 (21:30 +0000)
committerBrett Cannon <bcannon@gmail.com>
Mon, 28 Apr 2003 21:30:13 +0000 (21:30 +0000)
Lib/_strptime.py
Lib/test/test_strptime.py

index 81c105f758d7ed7f56c89bdfaab8fadd0a46fe85..4b7a7dd61510d1416d39f933249862425c4deea4 100644 (file)
@@ -423,6 +423,9 @@ def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
     found = format_regex.match(data_string)
     if not found:
         raise ValueError("time data did not match format")
+    if len(data_string) != found.end():
+        raise ValueError("unconverted data remains: %s" %
+                          data_string[found.end():])
     year = 1900
     month = day = 1
     hour = minute = second = 0
index a106a4289daabfdbacda3c93a1221c1e5c6ed7fb..2c3955b4a3b48e4c955596a97433754570cd948f 100644 (file)
@@ -227,6 +227,10 @@ class StrptimeTests(unittest.TestCase):
         self.assertRaises(ValueError, _strptime.strptime, data_string="%d",
                           format="%A")
 
+    def test_unconverteddata(self):
+        # Check ValueError is raised when there is unconverted data
+        self.assertRaises(ValueError, _strptime.strptime, "10 12", "%m")
+
     def helper(self, directive, position):
         """Helper fxn in testing."""
         strf_output = time.strftime("%" + directive, self.time_tuple)