]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Add tests for time.strftime() with invalid format string (GH-125696)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 18 Oct 2024 13:51:29 +0000 (16:51 +0300)
committerGitHub <noreply@github.com>
Fri, 18 Oct 2024 13:51:29 +0000 (16:51 +0300)
Lib/test/test_time.py

index f8b99a9b6a63f5732ae73c88cbd19f756fdca55e..d368f08b610870ce4e59d9fdae53c26dba565477 100644 (file)
@@ -18,7 +18,7 @@ try:
 except ImportError:
     _testinternalcapi = None
 
-from test.support import skip_if_buggy_ucrt_strfptime
+from test.support import skip_if_buggy_ucrt_strfptime, SuppressCrashReport
 
 # Max year is only limited by the size of C int.
 SIZEOF_INT = sysconfig.get_config_var('SIZEOF_INT') or 4
@@ -182,6 +182,17 @@ class TimeTestCase(unittest.TestCase):
 
         self.assertRaises(TypeError, time.strftime, b'%S', tt)
 
+    def test_strftime_invalid_format(self):
+        tt = time.gmtime(self.t)
+        with SuppressCrashReport():
+            for i in range(1, 128):
+                format = ' %' + chr(i)
+                with self.subTest(format=format):
+                    try:
+                        time.strftime(format, tt)
+                    except ValueError as exc:
+                        self.assertEqual(str(exc), 'Invalid format string')
+
     def test_strftime_special(self):
         tt = time.gmtime(self.t)
         s1 = time.strftime('%c', tt)