]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix some endcase bugs in unicode rfind()/rindex() and endswith().
authorGuido van Rossum <guido@python.org>
Tue, 20 Aug 2002 16:57:58 +0000 (16:57 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 20 Aug 2002 16:57:58 +0000 (16:57 +0000)
These were reported and fixed by Inyeol Lee in SF bug 595350.  The
endswith() bug is already fixed in 2.3; I'll fix the others in
2.3 next.

Lib/test/test_unicode.py
Misc/ACKS
Objects/stringobject.c
Objects/unicodeobject.c

index 411801986709d92f12a973d12e7065a25d1169b0..5d1c35a6d36f93572ebba9de7c7a710085924d9c 100644 (file)
@@ -83,6 +83,10 @@ test('find', u'abcdefghiabc', 9, u'abc', 1)
 test('find', u'abcdefghiabc', -1, u'def', 4)
 
 test('rfind', u'abcdefghiabc', 9, u'abc')
+test('rfind', 'abcdefghiabc', 9, u'abc')
+test('rfind', 'abcdefghiabc', 12, u'')
+test('rfind', u'abcdefghiabc', 12, '')
+test('rfind', u'abcdefghiabc', 12, u'')
 
 test('lower', u'HeLLo', u'hello')
 test('lower', u'hello', u'hello')
@@ -211,6 +215,8 @@ test('endswith', u'helloworld', 0, u'lowo', 4, 7)
 test('endswith', u'helloworld', 0, u'lowo', 3, 8)
 test('endswith', u'ab', 0, u'ab', 0, 1)
 test('endswith', u'ab', 0, u'ab', 0, 0)
+test('endswith', 'helloworld', 1, u'd')
+test('endswith', 'helloworld', 0, u'l')
 
 test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab      def\ng       hi')
 test('expandtabs', u'abc\rab\tdef\ng\thi', u'abc\rab      def\ng       hi', 8)
index 56a7efe0275c22efb47ae3a978ea96eba2ebe3e4..a543a4e30ae54701db366cbb46e01b6e0c60d6d6 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -257,6 +257,7 @@ Soren Larsen
 Piers Lauder
 Chris Lawrence
 Christopher Lee
+Inyeol Lee
 Kip Lehman
 Marc-Andre Lemburg
 William Lewis
index 7311df04a4007c59e629702b3ea56195d3276043..529a424d8a1ab4e10ba16dbad276a33b601fdeeb 100644 (file)
@@ -1303,7 +1303,7 @@ string_find_internal(PyStringObject *self, PyObject *args, int dir)
        }
 #ifdef Py_USING_UNICODE
        else if (PyUnicode_Check(subobj))
-               return PyUnicode_Find((PyObject *)self, subobj, i, last, 1);
+               return PyUnicode_Find((PyObject *)self, subobj, i, last, dir);
 #endif
        else if (PyObject_AsCharBuffer(subobj, &sub, &n))
                return -2;
@@ -2145,7 +2145,7 @@ string_startswith(PyStringObject *self, PyObject *args)
        const char* prefix;
        int plen;
        int start = 0;
-       int end = -1;
+       int end = INT_MAX;
        PyObject *subobj;
 
        if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &subobj,
@@ -2204,7 +2204,7 @@ string_endswith(PyStringObject *self, PyObject *args)
        const char* suffix;
        int slen;
        int start = 0;
-       int end = -1;
+       int end = INT_MAX;
        int lower, upper;
        PyObject *subobj;
 
index 5232aa3355576dc409721c1fb9cce44240af6d23..d4e247196dfb512f0faaa022500b1f96813e3c8e 100644 (file)
@@ -2866,9 +2866,6 @@ int findstring(PyUnicodeObject *self,
     if (start < 0)
         start = 0;
 
-    if (substring->length == 0)
-        return start;
-
     if (end > self->length)
         end = self->length;
     if (end < 0)
@@ -2876,6 +2873,9 @@ int findstring(PyUnicodeObject *self,
     if (end < 0)
         end = 0;
 
+    if (substring->length == 0)
+       return (direction > 0) ? start : end;
+
     end -= substring->length;
 
     if (direction < 0) {