mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
[3.11] gh-98744: Prevent column-level decoding crashes on traceback module (#98850)
Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
This commit is contained in:
parent
12957d7cbd
commit
751da28feb
3 changed files with 63 additions and 14 deletions
|
@ -778,6 +778,56 @@ class TracebackErrorLocationCaretTests(unittest.TestCase):
|
|||
]
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_wide_characters_unicode_with_problematic_byte_offset(self):
|
||||
def f():
|
||||
width
|
||||
|
||||
actual = self.get_exception(f)
|
||||
expected = [
|
||||
f"Traceback (most recent call last):",
|
||||
f" File \"{__file__}\", line {self.callable_line}, in get_exception",
|
||||
f" callable()",
|
||||
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 1}, in f",
|
||||
f" width",
|
||||
]
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
|
||||
def test_byte_offset_with_wide_characters_middle(self):
|
||||
def f():
|
||||
width = 1
|
||||
raise ValueError(width)
|
||||
|
||||
actual = self.get_exception(f)
|
||||
expected = [
|
||||
f"Traceback (most recent call last):",
|
||||
f" File \"{__file__}\", line {self.callable_line}, in get_exception",
|
||||
f" callable()",
|
||||
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 2}, in f",
|
||||
f" raise ValueError(width)",
|
||||
]
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
def test_byte_offset_multiline(self):
|
||||
def f():
|
||||
www = 1
|
||||
th = 0
|
||||
|
||||
print(1, www(
|
||||
th))
|
||||
|
||||
actual = self.get_exception(f)
|
||||
expected = [
|
||||
f"Traceback (most recent call last):",
|
||||
f" File \"{__file__}\", line {self.callable_line}, in get_exception",
|
||||
f" callable()",
|
||||
f" File \"{__file__}\", line {f.__code__.co_firstlineno + 4}, in f",
|
||||
f" print(1, www(",
|
||||
f" ^^^^",
|
||||
]
|
||||
self.assertEqual(actual, expected)
|
||||
|
||||
|
||||
@cpython_only
|
||||
@requires_debug_ranges()
|
||||
class CPythonTracebackErrorCaretTests(TracebackErrorLocationCaretTests):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue