summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-02-03 09:04:19 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-02-03 09:04:19 (GMT)
commit83e802796c80f46be616b48020356f7f51be533d (patch)
treee896b143abc3523f96e20d88ebcc22512af16aa7 /Modules
parent32ca3dcb97a75c05dc2b90c88bbf82a541c57c61 (diff)
downloadcpython-83e802796c80f46be616b48020356f7f51be533d.zip
cpython-83e802796c80f46be616b48020356f7f51be533d.tar.gz
cpython-83e802796c80f46be616b48020356f7f51be533d.tar.bz2
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.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_sre.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c
index 63778f4..9550d97 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -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;