sre.split should return the last segment, even if empty
(sorry, barry)
This commit is contained in:
parent
5c66a26dee
commit
f864aa8fd9
|
@ -155,6 +155,7 @@ if verbose:
|
|||
print 'Running tests on sre.split'
|
||||
|
||||
test(r"""sre.split(r":", ":a:b::c")""", ['', 'a', 'b', '', 'c'])
|
||||
test(r"""sre.split(r":+", ":a:b:::")""", ['', 'a', 'b', ''])
|
||||
test(r"""sre.split(r":*", ":a:b::c")""", ['', 'a', 'b', 'c'])
|
||||
test(r"""sre.split(r"(:*)", ":a:b::c")""", ['', ':', 'a', ':', 'b', '::', 'c'])
|
||||
test(r"""sre.split(r"(?::*)", ":a:b::c")""", ['', 'a', 'b', 'c'])
|
||||
|
|
|
@ -2007,17 +2007,16 @@ pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
|
|||
|
||||
}
|
||||
|
||||
/* get segment following last match */
|
||||
i = STATE_OFFSET(&state, last);
|
||||
if (i < state.endpos) {
|
||||
item = PySequence_GetSlice(string, i, state.endpos);
|
||||
if (!item)
|
||||
goto error;
|
||||
status = PyList_Append(list, item);
|
||||
Py_DECREF(item);
|
||||
if (status < 0)
|
||||
goto error;
|
||||
}
|
||||
/* get segment following last match (even if empty) */
|
||||
item = PySequence_GetSlice(
|
||||
string, STATE_OFFSET(&state, last), state.endpos
|
||||
);
|
||||
if (!item)
|
||||
goto error;
|
||||
status = PyList_Append(list, item);
|
||||
Py_DECREF(item);
|
||||
if (status < 0)
|
||||
goto error;
|
||||
|
||||
state_fini(&state);
|
||||
return list;
|
||||
|
|
Loading…
Reference in New Issue