Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da45d55

Browse files
committed
The strop module and test_strop.py believe replace() with a 0 count
means "replace everything". But the string module, string.replace() amd test_string.py believe a 0 count means "replace nothing". "Nothing" wins, strop loses. Bugfix candidate.
1 parent 9c012af commit da45d55

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

Lib/test/test_strop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __getitem__(self, i): return self.seq[i]
7777
test('replace', 'one!two!three!', 'one@two@three!', '!', '@', 2)
7878
test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 3)
7979
test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 4)
80-
test('replace', 'one!two!three!', 'one@two@three@', '!', '@', 0)
80+
test('replace', 'one!two!three!', 'one!two!three!', '!', '@', 0)
8181
test('replace', 'one!two!three!', 'one@two@three@', '!', '@')
8282
test('replace', 'one!two!three!', 'one!two!three!', 'x', '@')
8383
test('replace', 'one!two!three!', 'one!two!three!', 'x', '@', 2)

Modules/stropmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ strop_replace(PyObject *self, PyObject *args)
11211121
{
11221122
char *str, *pat,*sub,*new_s;
11231123
int len,pat_len,sub_len,out_len;
1124-
int count = 0;
1124+
int count = -1;
11251125
PyObject *new;
11261126

11271127
if (!PyArg_ParseTuple(args, "t#t#t#|i:replace",

0 commit comments

Comments
 (0)