Skip to content

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 11 commits into from
Oct 8, 2024

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Oct 3, 2024

@picnixz picnixz changed the title gh-123378: fix a crash in Unicode{Encode,Decode}Error.__str__ gh-123378: fix a crash in UnicodeError.__str__ Oct 4, 2024
@picnixz picnixz force-pushed the fix/unicode-error-str-123378 branch from 5ca7f92 to 360c1a5 Compare October 5, 2024 10:28
@picnixz picnixz requested a review from encukou October 5, 2024 10:37
Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, thank you!

@picnixz picnixz requested a review from encukou October 7, 2024 14:40
@@ -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),
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No you're right. I'll remove it.

@@ -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):
Copy link
Member

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.

(str, repr),
range(-5, 5),
range(-5, 5),
('', 'a', '123', '1234', '12345', 'abc123'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
('', 'a', '123', '1234', '12345', 'abc123'),
('', 'a', 'abc', 'abcde', 'abcdef'),

@picnixz picnixz requested a review from vstinner October 8, 2024 09:07
@vstinner vstinner merged commit ba14dfa into python:main Oct 8, 2024
37 checks passed
@vstinner vstinner added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Oct 8, 2024
@miss-islington-app
Copy link

Thanks @picnixz for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @picnixz for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 8, 2024
(cherry picked from commit ba14dfa)

Co-authored-by: Bénédikt Tran <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 8, 2024
(cherry picked from commit ba14dfa)

Co-authored-by: Bénédikt Tran <[email protected]>
@bedevere-app
Copy link

bedevere-app bot commented Oct 8, 2024

GH-125098 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 only security fixes label Oct 8, 2024
@bedevere-app
Copy link

bedevere-app bot commented Oct 8, 2024

GH-125099 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Oct 8, 2024
@picnixz picnixz deleted the fix/unicode-error-str-123378 branch October 8, 2024 11:50
vstinner pushed a commit that referenced this pull request Oct 8, 2024
…125098)

gh-123378: fix a crash in `UnicodeError.__str__` (GH-124935)
(cherry picked from commit ba14dfa)

Co-authored-by: Bénédikt Tran <[email protected]>
vstinner pushed a commit that referenced this pull request Oct 8, 2024
…125099)

gh-123378: fix a crash in `UnicodeError.__str__` (GH-124935)
(cherry picked from commit ba14dfa)

Co-authored-by: Bénédikt Tran <[email protected]>
efimov-mikhail pushed a commit to efimov-mikhail/cpython that referenced this pull request Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants