summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-03-29 16:21:02 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-03-29 16:21:02 (GMT)
commit48070c1248c97238493025553fe474ad9eca168d (patch)
tree059690cc3ec037f389723ab59d364cd18fe643ea
parent9db55004a1bc0c0b3efca69dcd577ff58a86ea16 (diff)
downloadcpython-48070c1248c97238493025553fe474ad9eca168d.zip
cpython-48070c1248c97238493025553fe474ad9eca168d.tar.gz
cpython-48070c1248c97238493025553fe474ad9eca168d.tar.bz2
Issue #23803: Fixed str.partition() and str.rpartition() when a separator
is wider then partitioned string.
-rw-r--r--Lib/test/test_unicode.py2
-rw-r--r--Misc/NEWS3
-rw-r--r--Objects/unicodeobject.c10
3 files changed, 10 insertions, 5 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 13a01f9..5efbe3e 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -375,6 +375,7 @@ class UnicodeTest(string_tests.CommonTest,
def test_partition(self):
string_tests.MixinStrUnicodeUserStringTest.test_partition(self)
# test mixed kinds
+ self.checkequal(('ABCDEFGH', '', ''), 'ABCDEFGH', 'partition', '\u4200')
for left, right in ('ba', '\u0101\u0100', '\U00010301\U00010300'):
left *= 9
right *= 9
@@ -391,6 +392,7 @@ class UnicodeTest(string_tests.CommonTest,
def test_rpartition(self):
string_tests.MixinStrUnicodeUserStringTest.test_rpartition(self)
# test mixed kinds
+ self.checkequal(('', '', 'ABCDEFGH'), 'ABCDEFGH', 'rpartition', '\u4200')
for left, right in ('ba', '\u0101\u0100', '\U00010301\U00010300'):
left *= 9
right *= 9
diff --git a/Misc/NEWS b/Misc/NEWS
index 7075ef8..c6b5e1c 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ Release date: tba
Core and Builtins
-----------------
+- Issue #23803: Fixed str.partition() and str.rpartition() when a separator
+ is wider then partitioned string.
+
- Issue #23192: Fixed generator lambdas. Patch by Bruno Cauet.
- Issue #23629: Fix the default __sizeof__ implementation for variable-sized
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 42cda58..b425e43 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -12681,7 +12681,7 @@ PyUnicode_Partition(PyObject *str_in, PyObject *sep_in)
len1 = PyUnicode_GET_LENGTH(str_obj);
len2 = PyUnicode_GET_LENGTH(sep_obj);
- switch (PyUnicode_KIND(str_obj)) {
+ switch (kind) {
case PyUnicode_1BYTE_KIND:
if (PyUnicode_IS_ASCII(str_obj) && PyUnicode_IS_ASCII(sep_obj))
out = asciilib_partition(str_obj, buf1, len1, sep_obj, buf2, len2);
@@ -12737,12 +12737,12 @@ PyUnicode_RPartition(PyObject *str_in, PyObject *sep_in)
return NULL;
}
- kind1 = PyUnicode_KIND(str_in);
+ kind1 = PyUnicode_KIND(str_obj);
kind2 = PyUnicode_KIND(sep_obj);
kind = Py_MAX(kind1, kind2);
- buf1 = PyUnicode_DATA(str_in);
+ buf1 = PyUnicode_DATA(str_obj);
if (kind1 != kind)
- buf1 = _PyUnicode_AsKind(str_in, kind);
+ buf1 = _PyUnicode_AsKind(str_obj, kind);
if (!buf1)
goto onError;
buf2 = PyUnicode_DATA(sep_obj);
@@ -12753,7 +12753,7 @@ PyUnicode_RPartition(PyObject *str_in, PyObject *sep_in)
len1 = PyUnicode_GET_LENGTH(str_obj);
len2 = PyUnicode_GET_LENGTH(sep_obj);
- switch (PyUnicode_KIND(str_in)) {
+ switch (kind) {
case PyUnicode_1BYTE_KIND:
if (PyUnicode_IS_ASCII(str_obj) && PyUnicode_IS_ASCII(sep_obj))
out = asciilib_rpartition(str_obj, buf1, len1, sep_obj, buf2, len2);