]> granicus.if.org Git - python/commitdiff
changed count to return 0 for slices outside the source string
authorFredrik Lundh <fredrik@pythonware.com>
Tue, 30 May 2006 17:39:58 +0000 (17:39 +0000)
committerFredrik Lundh <fredrik@pythonware.com>
Tue, 30 May 2006 17:39:58 +0000 (17:39 +0000)
Lib/test/string_tests.py
Objects/stringlib/count.h

index c2e0875b768b446a64461cf35486f2c963f0f4f3..8962c1f07a7314b98559588176f657a8aeb4b800 100644 (file)
@@ -115,7 +115,8 @@ class CommonTest(unittest.TestCase):
         self.checkequal(2, 'aaa', 'count', 'a', 0, -1)
         self.checkequal(0, 'aaa', 'count', 'a', 0, -10)
         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(4, 'aaa', 'count', '', -10)
 
index 84a852f52e49fd8743607953ab7b2c6103094839..367a15c51a5d4872214b3e78682d96da403665ea 100644 (file)
@@ -15,7 +15,7 @@ stringlib_count(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
 
     if (sub_len == 0) {
         if (str_len < 0)
-            return 1; /* start >= len(str) */
+            return 0; /* start > len(str) */
         return str_len + 1;
     }