Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests on truncated UTF-8 format strings
  • Loading branch information
vstinner committed Jun 11, 2024
commit d04269ff6ea5d129be59ef1668c93ec3fca88eae
8 changes: 7 additions & 1 deletion Lib/test/test_capi/test_unicode.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def check_format(expected, format, *args):
text = PyUnicode_FromFormat(format, *args)
self.assertEqual(expected, text)

# ascii format, non-ascii argument
# ASCII format, non-ASCII %U argument
check_format('ascii\x7f=unicode\xe9',
b'ascii\x7f=%U', 'unicode\xe9')

Expand All @@ -392,6 +392,12 @@ def check_format(expected, format, *args):
PyUnicode_FromFormat(b'invalid format string\xff: %s', b'abc')
Comment thread
vstinner marked this conversation as resolved.
self.assertIsInstance(cm.exception.__context__, UnicodeDecodeError)

# Truncated UTF-8 format strings
with self.assertRaisesRegex(ValueError, 'format string'):
PyUnicode_FromFormat(b'truncated utf8: \xc3')
with self.assertRaisesRegex(ValueError, 'format string'):
PyUnicode_FromFormat(b'truncated utf8: \xe2\x82')

# test "%c"
check_format('\uabcd',
b'%c', c_int(0xabcd))
Expand Down