GitLab will be upgraded on June 2nd 2020 at 2.00 pm (AEDT) to 3.00 pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to local Gitlab admin team.

Commit df751093 authored by Armin Rigo's avatar Armin Rigo

Issue #1849: fix for str.split(), str.rsplit()

parent 49fc87fa
......@@ -731,6 +731,22 @@ class W_BytesObject(W_AbstractBytesObject):
return space.wrap(self._val(space).join(l))
return self._StringMethods_descr_join(space, w_list)
_StringMethods_descr_split = descr_split
@unwrap_spec(maxsplit=int)
def descr_split(self, space, w_sep=None, maxsplit=-1):
if w_sep is not None and space.isinstance_w(w_sep, space.w_unicode):
self_as_uni = unicode_from_encoded_object(space, self, None, None)
return self_as_uni.descr_split(space, w_sep, maxsplit)
return self._StringMethods_descr_split(space, w_sep, maxsplit)
_StringMethods_descr_rsplit = descr_rsplit
@unwrap_spec(maxsplit=int)
def descr_rsplit(self, space, w_sep=None, maxsplit=-1):
if w_sep is not None and space.isinstance_w(w_sep, space.w_unicode):
self_as_uni = unicode_from_encoded_object(space, self, None, None)
return self_as_uni.descr_rsplit(space, w_sep, maxsplit)
return self._StringMethods_descr_rsplit(space, w_sep, maxsplit)
def _join_return_one(self, space, w_obj):
return (space.is_w(space.type(w_obj), space.w_str) or
space.is_w(space.type(w_obj), space.w_unicode))
......
......@@ -175,6 +175,24 @@ class AppTestUnicodeString:
assert u' a b c '.rsplit(None, 0) == [u' a b c']
assert u''.rsplit('aaa') == [u'']
def test_split_rsplit_str_unicode(self):
x = 'abc'.split(u'b')
assert x == [u'a', u'c']
assert map(type, x) == [unicode, unicode]
x = 'abc'.rsplit(u'b')
assert x == [u'a', u'c']
assert map(type, x) == [unicode, unicode]
x = 'abc'.split(u'\u4321')
assert x == [u'abc']
assert map(type, x) == [unicode]
x = 'abc'.rsplit(u'\u4321')
assert x == [u'abc']
assert map(type, x) == [unicode]
raises(UnicodeDecodeError, '\x80'.split, u'a')
raises(UnicodeDecodeError, '\x80'.split, u'')
raises(UnicodeDecodeError, '\x80'.rsplit, u'a')
raises(UnicodeDecodeError, '\x80'.rsplit, u'')
def test_center(self):
s=u"a b"
assert s.center(0) == u"a b"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment