mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Unicode replace() method with empty pattern argument should fail, like
it does for 8-bit strings.
This commit is contained in:
parent
3bc3f28dbe
commit
f36921c4b0
2 changed files with 11 additions and 0 deletions
|
@ -206,6 +206,12 @@ test('replace', u'one!two!three!', u'one!two!three!', u'!', u'@', 0)
|
||||||
test('replace', u'one!two!three!', u'one@two@three@', u'!', u'@')
|
test('replace', u'one!two!three!', u'one@two@three@', u'!', u'@')
|
||||||
test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@')
|
test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@')
|
||||||
test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@', 2)
|
test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@', 2)
|
||||||
|
try:
|
||||||
|
u"abc".replace(u"", u"x")
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
raise TestFailed, "u.replace('', ...) should raise ValueError"
|
||||||
|
|
||||||
test('startswith', u'hello', True, u'he')
|
test('startswith', u'hello', True, u'he')
|
||||||
test('startswith', u'hello', True, u'hello')
|
test('startswith', u'hello', True, u'hello')
|
||||||
|
|
|
@ -3455,6 +3455,11 @@ PyObject *replace(PyUnicodeObject *self,
|
||||||
{
|
{
|
||||||
PyUnicodeObject *u;
|
PyUnicodeObject *u;
|
||||||
|
|
||||||
|
if (str1->length == 0) {
|
||||||
|
PyErr_SetString(PyExc_ValueError, "empty pattern string");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (maxcount < 0)
|
if (maxcount < 0)
|
||||||
maxcount = INT_MAX;
|
maxcount = INT_MAX;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue