Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1ba5e65

Browse files
miss-islingtonJelleZijlstrapicnixz
authored
[3.14]gh-134119: Fix crash from calling next() on exhausted template iterator (GH-134120) (#134153)
gh-134119: Fix crash from calling next() on exhausted template iterator (GH-134120)(cherry picked from commitfc7f4c3)Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
1 parentcca18fc commit1ba5e65

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

‎Lib/test/test_string/test_templatelib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ def test_iter(self):
148148
self.assertEqual(res[1].format_spec,'')
149149
self.assertEqual(res[2],' yz')
150150

151+
deftest_exhausted(self):
152+
# See https://github.com/python/cpython/issues/134119.
153+
template_iter=iter(t"{1}")
154+
self.assertIsInstance(next(template_iter),Interpolation)
155+
self.assertRaises(StopIteration,next,template_iter)
156+
self.assertRaises(StopIteration,next,template_iter)
157+
151158

152159
if__name__=='__main__':
153160
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix crash when calling:func:`next` on an exhausted template string iterator.
2+
Patch by Jelle Zijlstra.

‎Objects/templateobject.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ templateiter_next(PyObject *op)
2323
if (self->from_strings) {
2424
item=PyIter_Next(self->stringsiter);
2525
self->from_strings=0;
26+
if (item==NULL) {
27+
returnNULL;
28+
}
2629
if (PyUnicode_GET_LENGTH(item)==0) {
2730
Py_SETREF(item,PyIter_Next(self->interpolationsiter));
2831
self->from_strings=1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp