diff options
author | Guido van Rossum <guido@python.org> | 2002-08-20 17:29:29 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-08-20 17:29:29 (GMT) |
commit | 76afbd9aa41bf34f488a7a1e759622c7f1830cff (patch) | |
tree | e4fb84ab073d0da8a668381b45dae2cb96c92c6a | |
parent | c230b0e1f92bdc54318d58a07859bfcd7b03979a (diff) | |
download | cpython-76afbd9aa41bf34f488a7a1e759622c7f1830cff.zip cpython-76afbd9aa41bf34f488a7a1e759622c7f1830cff.tar.gz cpython-76afbd9aa41bf34f488a7a1e759622c7f1830cff.tar.bz2 |
Fix some endcase bugs in unicode rfind()/rindex() and endswith().
These were reported and fixed by Inyeol Lee in SF bug 595350. The
endswith() bug was already fixed in 2.3, but this adds some more test
cases.
-rw-r--r-- | Lib/test/test_unicode.py | 6 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Objects/stringobject.c | 2 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 6 |
4 files changed, 11 insertions, 4 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py index f5f4245..4efa39c 100644 --- a/Lib/test/test_unicode.py +++ b/Lib/test/test_unicode.py @@ -107,6 +107,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') @@ -241,6 +245,8 @@ test('endswith', u'helloworld', False, u'lowo', 4, 7) test('endswith', u'helloworld', False, u'lowo', 3, 8) test('endswith', u'ab', False, u'ab', 0, 1) test('endswith', u'ab', False, u'ab', 0, 0) +test('endswith', 'helloworld', True, u'd') +test('endswith', 'helloworld', False, 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) @@ -292,6 +292,7 @@ Soren Larsen Piers Lauder Chris Lawrence Christopher Lee +Inyeol Lee Luc Lefebvre Kip Lehman Marc-Andre Lemburg diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 7a48627..9f41317 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -1536,7 +1536,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; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4ac12a0..b264936 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -2891,9 +2891,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) @@ -2901,6 +2898,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) { |