]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] Add tests for time.strftime() with invalid format string (GH-125696) (GH-125701)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 18 Oct 2024 14:13:31 +0000 (16:13 +0200)
committerGitHub <noreply@github.com>
Fri, 18 Oct 2024 14:13:31 +0000 (14:13 +0000)
(cherry picked from commit 2e950e341930ea79549137d4d3771d5edb940e65)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_time.py

index b020787dacac1c7c70adad8e599e9705b92db3b6..9463adda88db0dbc88f6a3848c5565bacfa91aed 100644 (file)
@@ -14,7 +14,7 @@ try:
 except ImportError:
     _testcapi = 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
@@ -178,6 +178,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)