]> granicus.if.org Git - python/commitdiff
sre.split should return the last segment, even if empty
authorFredrik Lundh <fredrik@pythonware.com>
Mon, 22 Oct 2001 06:01:56 +0000 (06:01 +0000)
committerFredrik Lundh <fredrik@pythonware.com>
Mon, 22 Oct 2001 06:01:56 +0000 (06:01 +0000)
(sorry, barry)

Lib/test/test_sre.py
Modules/_sre.c

index e8791519d50c493c2d903163c64e0b0c45a889be..75a168cb9c06413269807c955657c7a576d5d657 100644 (file)
@@ -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'])
index 5573046d1fab61120631cb917692ac3e104e1ebf..73ffa70d1e49d32cdc43add3a08cca5a0dc5e092 100644 (file)
@@ -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;