8000 gh-119182: Decode PyUnicode_FromFormat() format string from UTF-8 by vstinner · Pull Request #120248 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119182: Decode PyUnicode_FromFormat() format string from UTF-8 #120248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
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')
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
Loading
0