[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 commit fc7f4c3666)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
Miss Islington (bot) 2025-05-17 21:48:54 +02:00 committed by GitHub
parent cca18fcbe8
commit 1ba5e65b76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 0 deletions

View file

@ -23,6 +23,9 @@ templateiter_next(PyObject *op)
if (self->from_strings) {
item = PyIter_Next(self->stringsiter);
self->from_strings = 0;
if (item == NULL) {
return NULL;
}
if (PyUnicode_GET_LENGTH(item) == 0) {
Py_SETREF(item, PyIter_Next(self->interpolationsiter));
self->from_strings = 1;