]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Guido has Spoken. Restore strop.replace()'s treatment of a 0 count as
authorTim Peters <tim.peters@gmail.com>
Thu, 10 May 2001 01:23:39 +0000 (01:23 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 10 May 2001 01:23:39 +0000 (01:23 +0000)
meaning infinity -- but at least warn about it in the code!  I pissed
away a couple hours on this today, and don't wish the same on the next
in line.
Bugfix candidate.

Lib/test/test_strop.py
Modules/stropmodule.c

index de7a7959ff6329d1d908c3dcc26643578d42988e..9130088eff545624a0762db7a888a5c23163cac0 100644 (file)
@@ -77,7 +77,9 @@ test('replace', 'one!two!three!', 'one@two!three!', '!', '@', 1)
 test('replace', 'one!two!three!', 'one@two@three!', '!', '@', 2)
 test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 3)
 test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 4)
-test('replace', 'one!two!three!', 'one!two!three!', '!', '@', 0)
+# CAUTION:  a replace count of 0 means infinity only to strop, not to the
+# string .replace() method or to the string.replace() function.
+test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 0)
 test('replace', 'one!two!three!', 'one@two@three@', '!', '@')
 test('replace', 'one!two!three!', 'one!two!three!', 'x', '@')
 test('replace', 'one!two!three!', 'one!two!three!', 'x', '@', 2)
index aa9cdc76a052820738526277c4062e9b0377e582..312e0dc98122185b6d16619a31d7088ecb61b02c 100644 (file)
@@ -1132,6 +1132,12 @@ strop_replace(PyObject *self, PyObject *args)
                PyErr_SetString(PyExc_ValueError, "empty pattern string");
                return NULL;
        }
+       /* CAUTION:  strop treats a replace count of 0 as infinity, unlke
+        * current (2.1) string.py and string methods.  Preserve this for
+        * ... well, hard to say for what <wink>.
+        */
+       if (count == 0)
+               count = -1;
        new_s = mymemreplace(str,len,pat,pat_len,sub,sub_len,count,&out_len);
        if (new_s == NULL) {
                PyErr_NoMemory();