Skip to content
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

More strict format checks in PyUnicode_FromFormat() #95781

Closed
serhiy-storchaka opened this issue Aug 8, 2022 · 0 comments
Closed

More strict format checks in PyUnicode_FromFormat() #95781

serhiy-storchaka opened this issue Aug 8, 2022 · 0 comments
Assignees
Labels
topic-C-API type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

PyUnicode_FromFormat() is loose in checking for errors in the format string. If it encounter an invalid format specifier, it silently outputs the rest of the format string. And it allows digits between %s: "%123%" is interpreted the same as "%%", i.e. as literal %.

It was not a big problem, because it is expected that the user of the C API do not make mistakes in the format string, and incorrect format string can easily lead to crash. But id did not help either.

Recently it was discussed on Discuss: https://discuss.python.org/t/pyunicode-fromformat-allow-format-with-precision/17873.

@serhiy-storchaka serhiy-storchaka added the type-feature A feature request or enhancement label Aug 8, 2022
@serhiy-storchaka serhiy-storchaka self-assigned this Aug 8, 2022
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Aug 8, 2022
…ormatV()

SystemError is now raised if the format contains invalid format
specifiers. Previously it just silently output the rest of the format
string starting from the invalid specifier.
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Aug 8, 2022
…ormatV()

An unrecognized format character in PyUnicode_FromFormat() and
PyUnicode_FromFormatV() now sets a SystemError.
In previous versions it caused all the rest of the format string to be
copied as-is to the result string, and any extra arguments discarded.
serhiy-storchaka added a commit that referenced this issue Aug 8, 2022
…() (GH-95784)

An unrecognized format character in PyUnicode_FromFormat() and
PyUnicode_FromFormatV() now sets a SystemError.
In previous versions it caused all the rest of the format string to be
copied as-is to the result string, and any extra arguments discarded.
iritkatriel pushed a commit to iritkatriel/cpython that referenced this issue Aug 11, 2022
…ormatV() (pythonGH-95784)

An unrecognized format character in PyUnicode_FromFormat() and
PyUnicode_FromFormatV() now sets a SystemError.
In previous versions it caused all the rest of the format string to be
copied as-is to the result string, and any extra arguments discarded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-C-API type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant