mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #22818: Splitting on a pattern that could match an empty string now
raises a warning. Patterns that can only match empty strings are now rejected.
This commit is contained in:
parent
32ca3dcb97
commit
83e802796c
6 changed files with 85 additions and 20 deletions
|
@ -863,6 +863,19 @@ pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
|
|||
if (!string)
|
||||
return NULL;
|
||||
|
||||
assert(self->codesize != 0);
|
||||
if (self->code[0] != SRE_OP_INFO || self->code[3] == 0) {
|
||||
if (self->code[0] == SRE_OP_INFO && self->code[4] == 0) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"split() requires a non-empty pattern match.");
|
||||
return NULL;
|
||||
}
|
||||
if (PyErr_WarnEx(PyExc_FutureWarning,
|
||||
"split() requires a non-empty pattern match.",
|
||||
1) < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
string = state_init(&state, self, string, 0, PY_SSIZE_T_MAX);
|
||||
if (!string)
|
||||
return NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue