Skip to content

Commit 76478c2

Browse files
committed
fix fuzz test failed
1 parent 255fb8c commit 76478c2

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Lib/test/test_tstring.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ def test_debug_specifier(self):
162162
)
163163
self.assertEqual(fstring(t), "Value: value = 42")
164164

165+
def test_debug_specifier_with_reconstructed_metadata(self):
166+
regular = t'''{(
167+
1, # Force lexer metadata reconstruction.
168+
"\"#")}'''
169+
debug = t'''{(
170+
1, # Force lexer metadata reconstruction.
171+
"\"#")=}'''
172+
self.assertEqual(
173+
debug.interpolations[0].expression,
174+
regular.interpolations[0].expression,
175+
)
176+
165177
def test_raw_tstrings(self):
166178
path = r"C:\Users"
167179
t = rt"{path}\Documents"

Parser/action_helpers.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,10 @@ _strip_interpolation_debug_expr(PyObject *exprstr)
15521552
}
15531553
len--;
15541554
}
1555-
assert(len > 0 && PyUnicode_READ_CHAR(exprstr, len - 1) == '=');
1555+
/* The debug marker may be absent from reconstructed lexer metadata. */
1556+
if (len == 0 || PyUnicode_READ_CHAR(exprstr, len - 1) != '=') {
1557+
return Py_NewRef(exprstr);
1558+
}
15561559

15571560
return PyUnicode_Substring(exprstr, 0, len - 1);
15581561
}

0 commit comments

Comments
 (0)