Skip to content

Commit 2e950e3

Browse files
Add tests for time.strftime() with invalid format string (GH-125696)
1 parent cda0ec8 commit 2e950e3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Lib/test/test_time.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
except ImportError:
1919
_testinternalcapi = None
2020

21-
from test.support import skip_if_buggy_ucrt_strfptime
21+
from test.support import skip_if_buggy_ucrt_strfptime, SuppressCrashReport
2222

2323
# Max year is only limited by the size of C int.
2424
SIZEOF_INT = sysconfig.get_config_var('SIZEOF_INT') or 4
@@ -182,6 +182,17 @@ def test_strftime(self):
182182

183183
self.assertRaises(TypeError, time.strftime, b'%S', tt)
184184

185+
def test_strftime_invalid_format(self):
186+
tt = time.gmtime(self.t)
187+
with SuppressCrashReport():
188+
for i in range(1, 128):
189+
format = ' %' + chr(i)
190+
with self.subTest(format=format):
191+
try:
192+
time.strftime(format, tt)
193+
except ValueError as exc:
194+
self.assertEqual(str(exc), 'Invalid format string')
195+
185196
def test_strftime_special(self):
186197
tt = time.gmtime(self.t)
187198
s1 = time.strftime('%c', tt)

0 commit comments

Comments
 (0)