Index: src/org/python/core/PyString.java =================================================================== --- src/org/python/core/PyString.java (revision 3444) +++ src/org/python/core/PyString.java (working copy) @@ -2593,23 +2593,28 @@ } private PyList splitfields(String sep, int maxsplit) { - if (sep.length() == 0) { - throw Py.ValueError("empty separator"); - } PyList list = new PyList(); int length = string.length(); if (maxsplit < 0) - maxsplit = length; + maxsplit = length + 1; int lastbreak = 0; int splits = 0; int sepLength = sep.length(); + int index; + if((sep.length() == 0) && (maxsplit != 0) ) { + index = string.indexOf(sep, lastbreak); + list.append(fromSubstring(lastbreak, index)); + splits++; + } while (splits < maxsplit) { - int index = string.indexOf(sep, lastbreak); + index = string.indexOf(sep, lastbreak); if (index == -1) break; + if(sep.length() == 0) + index++; splits += 1; list.append(fromSubstring(lastbreak, index)); lastbreak = index + sepLength; @@ -3095,13 +3100,18 @@ } final PyString str_replace(PyObject oldPiece, PyObject newPiece) { - return str_replace(oldPiece, newPiece, string.length()); + if (!(oldPiece instanceof PyString) || (((PyString)oldPiece).string).length() == 0) + return str_replace(oldPiece, newPiece, string.length() + 1); + else + return str_replace(oldPiece, newPiece, string.length()); } final PyString str_replace(PyObject oldPiece, PyObject newPiece, int maxsplit) { if(!(oldPiece instanceof PyString) || !(newPiece instanceof PyString)){ throw Py.TypeError("str or unicode required for replace"); } + if (string.length() == 0) + return (new PyString(string)); return ((PyString)newPiece).str_join(str_split(((PyString)oldPiece).string, maxsplit)); } Index: Lib/test/string_tests.py =================================================================== --- Lib/test/string_tests.py (revision 3440) +++ Lib/test/string_tests.py (working copy) @@ -261,13 +261,10 @@ self.checkequal('one@two@three@', 'one!two!three!', 'replace', '!', '@') self.checkequal('one!two!three!', 'one!two!three!', 'replace', 'x', '@') self.checkequal('one!two!three!', 'one!two!three!', 'replace', 'x', '@', 2) -# Jython transition 2.3 -# str.replace doesn't handle an empty string to be replaced. -# http://jython.org/bugs/1768074 -# self.checkequal('-a-b-c-', 'abc', 'replace', '', '-') -# self.checkequal('-a-b-c', 'abc', 'replace', '', '-', 3) -# self.checkequal('abc', 'abc', 'replace', '', '-', 0) -# self.checkequal('', '', 'replace', '', '') + self.checkequal('-a-b-c-', 'abc', 'replace', '', '-') + self.checkequal('-a-b-c', 'abc', 'replace', '', '-', 3) + self.checkequal('abc', 'abc', 'replace', '', '-', 0) + self.checkequal('', '', 'replace', '', '') self.checkequal('abc', 'abc', 'replace', 'ab', '--', 0) self.checkequal('abc', 'abc', 'replace', 'xy', '--') # Next three for SF bug 422088: [OSF1 alpha] string.replace(); died with