Commit f4fc5e96 authored by Fredrik Lundh's avatar Fredrik Lundh

sre.split should return the last segment, even if empty

(sorry, barry)
parent 0452fb8d
...@@ -155,6 +155,7 @@ if verbose: ...@@ -155,6 +155,7 @@ if verbose:
print 'Running tests on sre.split' print 'Running tests on sre.split'
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:::")""", ['', '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']) 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) ...@@ -2007,17 +2007,16 @@ pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
} }
/* get segment following last match */ /* get segment following last match (even if empty) */
i = STATE_OFFSET(&state, last); item = PySequence_GetSlice(
if (i < state.endpos) { string, STATE_OFFSET(&state, last), state.endpos
item = PySequence_GetSlice(string, i, state.endpos); );
if (!item) if (!item)
goto error; goto error;
status = PyList_Append(list, item); status = PyList_Append(list, item);
Py_DECREF(item); Py_DECREF(item);
if (status < 0) if (status < 0)
goto error; goto error;
}
state_fini(&state); state_fini(&state);
return list; return list;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment