mirror of https://github.com/python/cpython
changed count to return 0 for slices outside the source string
This commit is contained in:
parent
4182a75571
commit
9e9ef9fa5a
|
@ -115,7 +115,8 @@ class CommonTest(unittest.TestCase):
|
||||||
self.checkequal(2, 'aaa', 'count', 'a', 0, -1)
|
self.checkequal(2, 'aaa', 'count', 'a', 0, -1)
|
||||||
self.checkequal(0, 'aaa', 'count', 'a', 0, -10)
|
self.checkequal(0, 'aaa', 'count', 'a', 0, -10)
|
||||||
self.checkequal(3, 'aaa', 'count', '', 1)
|
self.checkequal(3, 'aaa', 'count', '', 1)
|
||||||
self.checkequal(1, 'aaa', 'count', '', 10)
|
self.checkequal(1, 'aaa', 'count', '', 3)
|
||||||
|
self.checkequal(0, 'aaa', 'count', '', 10)
|
||||||
self.checkequal(2, 'aaa', 'count', '', -1)
|
self.checkequal(2, 'aaa', 'count', '', -1)
|
||||||
self.checkequal(4, 'aaa', 'count', '', -10)
|
self.checkequal(4, 'aaa', 'count', '', -10)
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ stringlib_count(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
|
||||||
|
|
||||||
if (sub_len == 0) {
|
if (sub_len == 0) {
|
||||||
if (str_len < 0)
|
if (str_len < 0)
|
||||||
return 1; /* start >= len(str) */
|
return 0; /* start > len(str) */
|
||||||
return str_len + 1;
|
return str_len + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue