-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
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
Changes from 9 commits
a9b1c0c
3567426
43141c0
0c61375
80287f6
7bbc0f5
2313cd1
a27a88b
360c1a5
85199f8
44dfaeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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,26 @@ 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 formatter, start, end, obj in product( | ||||||
(str, repr), | ||||||
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? 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), | ||||||
('', 'a', '123', '1234', '12345', 'abc123'), | ||||||
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.
Suggested change
|
||||||
): | ||||||
with self.subTest(formatter, obj=obj, start=start, end=end): | ||||||
exc = UnicodeEncodeError('utf-8', obj, start, end, '') | ||||||
self.assertIsInstance(formatter(exc), str) | ||||||
|
||||||
with self.subTest(formatter, obj=obj, start=start, end=end): | ||||||
exc = UnicodeTranslateError(obj, start, end, '') | ||||||
self.assertIsInstance(formatter(exc), str) | ||||||
|
||||||
encoded = obj.encode() | ||||||
with self.subTest(formatter, obj=encoded, start=start, end=end): | ||||||
exc = UnicodeDecodeError('utf-8', encoded, start, end, '') | ||||||
self.assertIsInstance(formatter(exc), str) | ||||||
|
||||||
@no_tracing | ||||||
def test_badisinstance(self): | ||||||
# Bug #2542: if issubclass(e, MyException) raises an exception, | ||||||
|
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. |
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.