gh-70278: Fix PyUnicode_FromFormat() with precision for %s and %V#120365
Merged
serhiy-storchaka merged 6 commits intopython:mainfrom Jun 24, 2024
Merged
Conversation
PyUnicode_FromFormat() no longer produces the ending \ufffd character for truncated C string when use precision with %s and %V. It now truncates the string before the start of truncated multibyte sequences.
vstinner
reviewed
Jun 12, 2024
vstinner
reviewed
Jun 12, 2024
Objects/unicodeobject.c
Outdated
| while (length < precision && str[length]) { | ||
| length++; | ||
| } | ||
| pconsumed = (length < precision) ? NULL : &consumed; |
Member
There was a problem hiding this comment.
Can you add a comment explaining why you set pconsumed? Explain the expected behavior of truncating incomplete sequence at the end, but still replace invalid sequence in the middle. Something like that :-) You can add a reference to the issue gh-70278.
…t-truncate' into PyUnicode_FromFormat-truncate
Member
|
Can you try to add an unit test? |
Member
Author
|
There are new tests in this PR. What other cases do you want to test? |
vstinner
approved these changes
Jun 24, 2024
Member
vstinner
left a comment
There was a problem hiding this comment.
LGTM.
For tests, GitHub didn't show me the whole diff when I clicked on a notification. I'm always confused by the UI, sorry.
mrahtz
pushed a commit
to mrahtz/cpython
that referenced
this pull request
Jun 30, 2024
…%V (pythonGH-120365) PyUnicode_FromFormat() no longer produces the ending \ufffd character for truncated C string when use precision with %s and %V. It now truncates the string before the start of truncated multibyte sequences.
noahbkim
pushed a commit
to hudson-trading/cpython
that referenced
this pull request
Jul 11, 2024
…%V (pythonGH-120365) PyUnicode_FromFormat() no longer produces the ending \ufffd character for truncated C string when use precision with %s and %V. It now truncates the string before the start of truncated multibyte sequences.
estyxx
pushed a commit
to estyxx/cpython
that referenced
this pull request
Jul 17, 2024
…%V (pythonGH-120365) PyUnicode_FromFormat() no longer produces the ending \ufffd character for truncated C string when use precision with %s and %V. It now truncates the string before the start of truncated multibyte sequences.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PyUnicode_FromFormat() no longer produces the ending \ufffd character for truncated C string when use precision with %s and %V. It now truncates the string before the start of truncated multibyte sequences.