Repository navigation
gh-123378: fix a crash in UnicodeError.__str__
#124935
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a9b1c0c
fix OOB in `UnicodeError.__str__`
picnixz 3567426
blurb
picnixz 43141c0
add tests
picnixz 0c61375
small fixup
picnixz 80287f6
Fix Windows compilation
picnixz 7bbc0f5
improve test coverage
picnixz 2313cd1
fix `UnicodeTranslateError`
picnixz a27a88b
improve test coverage
picnixz 360c1a5
revert cosmetic changes
picnixz 85199f8
add back PEP-7 braces
picnixz 44dfaeb
address Victor's review
picnixz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| import weakref | ||
| import errno | ||
| from codecs import BOM_UTF8 | ||
| from itertools import product | ||
| from textwrap import dedent | ||
|
|
||
| from test.support import (captured_stderr, check_impl_detail, | ||
|
|
@@ -1336,6 +1337,22 @@ def test_unicode_errors_no_object(self): | |
| for klass in klasses: | ||
| self.assertEqual(str(klass.__new__(klass)), "") | ||
|
|
||
| def test_unicode_error_str_gh_123378(self): | ||
| for meth, start, end in product( | ||
| (str, repr), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing repr() if we already test str() sounds redundant to me. Is it really worth it?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No you're right. I'll remove it. |
||
| range(-5, 5), | ||
| range(-5, 5), | ||
| ): | ||
| for obj in ('', 'a'): | ||
| with self.subTest(meth, obj=obj, start=start, end=end): | ||
| res = meth(UnicodeEncodeError('utf-8', obj, start, end, '')) | ||
| self.assertIsInstance(res, str) | ||
|
|
||
| for obj in (b'', b'a'): | ||
| with self.subTest(meth, obj=obj, start=start, end=end): | ||
| res = meth(UnicodeDecodeError('utf-8', obj, start, end, '')) | ||
| self.assertIsInstance(res, str) | ||
|
|
||
| @no_tracing | ||
| def test_badisinstance(self): | ||
| # Bug #2542: if issubclass(e, MyException) raises an exception, | ||
|
|
||
3 changes: 3 additions & 0 deletions
3
Misc/NEWS.d/next/Core_and_Builtins/2024-10-03-14-39-41.gh-issue-123378.dCxANf.rst
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Fix a crash in the :meth:`~object.__str__` method of :exc:`UnicodeError` | ||
| objects when the :attr:`UnicodeError.start` and :attr:`UnicodeError.end` | ||
| values are invalid or out-of-range. Patch by Bénédikt Tran. |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of the test is unclear to me, it just calls str(). Please add a comment to explain that you check that str() doesn't crash with a reference to the issue.