-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-134119: Fix crash from calling next() on exhausted template iterator #134120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix crash when calling :func:`next` on an exhausted template string iterator. | ||
Patch by Jelle Zijlstra. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the result of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That case just falls through to returning (The fall-through is intentional: since there is always one more There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
self->from_strings = 1; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it is worth to add condition here like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would potentially make an API call with an exception set, which is not allowed, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, good point. Thanks!