mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
gh-98744: Prevent column-level decoding crashes on traceback module (#98824)
This commit is contained in:
parent
7ea10567af
commit
c0f2a5ef91
3 changed files with 63 additions and 14 deletions
|
@ -804,6 +804,56 @@ class TracebackErrorLocationCaretTestBase:
|
|||
]
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@requires_debug_ranges()
|
||||
class PurePythonTracebackErrorCaretTests(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue