[pypy-commit] pypy utf8-unicode2: Fix byte-index / char-index mixup

waedt noreply at buildbot.pypy.org
Thu Jul 10 17:23:23 CEST 2014


Author: Tyler Wade <wayedt at gmail.com>
Branch: utf8-unicode2
Changeset: r72412:b286a841b645
Date: 2014-07-08 22:24 -0500
http://bitbucket.org/pypy/pypy/changeset/b286a841b645/

Log:	Fix byte-index / char-index mixup

diff --git a/pypy/objspace/std/test/test_unicodeobject.py b/pypy/objspace/std/test/test_unicodeobject.py
--- a/pypy/objspace/std/test/test_unicodeobject.py
+++ b/pypy/objspace/std/test/test_unicodeobject.py
@@ -380,7 +380,9 @@
         assert u'ab'.startswith(u'a', 1) is False
         assert u'ab'.startswith(u'b', 1) is True
         assert u'abc'.startswith(u'bc', 1, 2) is False
-        assert u'abc'.startswith(u'c', -1, 4) is True
+
+        assert u'\xE4bc'.startswith(u'\xE4') is True
+        assert u'\xE4\xE4bc'.startswith(u'\xE4', 1) is True
 
     def test_startswith_tuples(self):
         assert u'hello'.startswith((u'he', u'ha'))
diff --git a/pypy/objspace/std/unicodeobject.py b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -324,11 +324,11 @@
 
     def _startswith(self, space, value, w_prefix, start, end):
         return startswith(value.bytes, self._op_val(space, w_prefix).bytes,
-                          start, end)
+                          value.index_of_char(start), value.index_of_char(end))
 
     def _endswith(self, space, value, w_prefix, start, end):
         return endswith(value.bytes, self._op_val(space, w_prefix).bytes,
-                        start, end)
+                        value.index_of_char(start), value.index_of_char(end))
 
     @staticmethod
     def _split(value, sep=None, maxsplit=-1):


More information about the pypy-commit mailing list