diff -r 7255af1a1c50 Lib/test/string_tests.py --- a/Lib/test/string_tests.py Mon May 25 12:32:20 2015 +0300 +++ b/Lib/test/string_tests.py Mon May 25 14:28:43 2015 +0300 @@ -976,6 +976,9 @@ class MixinStrUnicodeUserStringTest: self.checkequal(True, 'helloworld', 'startswith', 'lowo', 3) self.checkequal(True, 'helloworld', 'startswith', 'lowo', 3, 7) self.checkequal(False, 'helloworld', 'startswith', 'lowo', 3, 6) + self.checkequal(True, '', 'startswith', '', 0, 1) + self.checkequal(True, '', 'startswith', '', 0, 0) + self.checkequal(False, '', 'startswith', '', 1, 0) # test negative indices self.checkequal(True, 'hello', 'startswith', 'he', 0, -1) @@ -1022,6 +1025,9 @@ class MixinStrUnicodeUserStringTest: self.checkequal(False, 'helloworld', 'endswith', 'lowo', 3, 8) self.checkequal(False, 'ab', 'endswith', 'ab', 0, 1) self.checkequal(False, 'ab', 'endswith', 'ab', 0, 0) + self.checkequal(True, '', 'endswith', '', 0, 1) + self.checkequal(True, '', 'endswith', '', 0, 0) + self.checkequal(False, '', 'endswith', '', 1, 0) # test negative indices self.checkequal(True, 'hello', 'endswith', 'lo', -2) diff -r 7255af1a1c50 Objects/unicodeobject.c --- a/Objects/unicodeobject.c Mon May 25 12:32:20 2015 +0300 +++ b/Objects/unicodeobject.c Mon May 25 14:28:43 2015 +0300 @@ -9280,14 +9280,14 @@ tailmatch(PyObject *self, PyUnicode_READY(substring) == -1) return -1; - if (PyUnicode_GET_LENGTH(substring) == 0) - return 1; - ADJUST_INDICES(start, end, PyUnicode_GET_LENGTH(self)); end -= PyUnicode_GET_LENGTH(substring); if (end < start) return 0; + if (PyUnicode_GET_LENGTH(substring) == 0) + return 1; + kind_self = PyUnicode_KIND(self); data_self = PyUnicode_DATA(self); kind_sub = PyUnicode_KIND(substring);