Skip to content

Commit afa0d58

Browse files
committed
Issue python#3751: str.rpartition would perform a left-partition when called with
a unicode argument. Backport of r66119
1 parent 50b1c49 commit afa0d58

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎Lib/test/string_tests.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,9 @@ def test_partition(self):
10661066
self.checkraises(ValueError, S, 'partition', '')
10671067
self.checkraises(TypeError, S, 'partition', None)
10681068

1069+
# mixed use of str and unicode
1070+
self.assertEqual('a/b/c'.partition(u'/'), ('a', '/', 'b/c'))
1071+
10691072
def test_rpartition(self):
10701073

10711074
self.checkequal(('this is the rparti', 'ti', 'on method'),
@@ -1081,6 +1084,8 @@ def test_rpartition(self):
10811084
self.checkraises(ValueError, S, 'rpartition', '')
10821085
self.checkraises(TypeError, S, 'rpartition', None)
10831086

1087+
# mixed use of str and unicode
1088+
self.assertEqual('a/b/c'.rpartition(u'/'), ('a/b', '/', 'c'))
10841089

10851090
class MixinStrStringUserStringTest:
10861091
# Additional tests for 8bit strings, i.e. str, UserString and

‎Misc/NEWS‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 2.5.3?
1212
Core and builtins
1313
-----------------
1414

15+
- Issue #3751: str.rpartition would perform a left-partition when called with
16+
a unicode argument.
17+
1518
- Issue #3537: Fix an assertion failure when an empty but presized dict
1619
object was stored in the freelist.
1720

‎Objects/stringobject.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ string_rpartition(PyStringObject *self, PyObject *sep_obj)
15951595
}
15961596
#ifdef Py_USING_UNICODE
15971597
else if (PyUnicode_Check(sep_obj))
1598-
return PyUnicode_Partition((PyObject *) self, sep_obj);
1598+
return PyUnicode_RPartition((PyObject *) self, sep_obj);
15991599
#endif
16001600
else if (PyObject_AsCharBuffer(sep_obj, &sep, &sep_len))
16011601
return NULL;

0 commit comments

Comments
 (0)