summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2001-01-16 11:54:12 +0000
committerMarc-André Lemburg <mal@egenix.com>2001-01-16 11:54:12 +0000
commit190b8a256fc775bd89ff9893e3cc00fe87b5f825 (patch)
tree2c856ca0ab1ee7cffb96d510f1b1404a52d7e621 /Lib
parentd0f46e380d3d154c187bcfe14bbde43a32865afb (diff)
downloadcpython-190b8a256fc775bd89ff9893e3cc00fe87b5f825.tar.gz
Added checks to prevent PyUnicode_Count() from dumping core
in case the parameters are out of bounds and fixes error handling for .count(), .startswith() and .endswith() for the case of mixed string/Unicode objects. This patch adds Python style index semantics to PyUnicode_Count() indices (including the special handling of negative indices). The patch is an extended version of patch #103249 submitted by Michael Hudson (mwh) on SF. It also includes new test cases.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/string_tests.py4
-rw-r--r--Lib/test/test_unicode.py7
2 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py
index d4041bec4a..067cccafc2 100644
--- a/Lib/test/string_tests.py
+++ b/Lib/test/string_tests.py
@@ -53,6 +53,10 @@ def run_method_tests(test):
test('capitalize', ' hello ', ' hello ')
test('capitalize', 'hello ', 'Hello ')
+
+ test('count', 'aaa', 3, 'a')
+ test('count', 'aaa', 0, 'b')
+
test('find', 'abcdefghiabc', 0, 'abc')
test('find', 'abcdefghiabc', 9, 'abc', 1)
test('find', 'abcdefghiabc', -1, 'def', 4)
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index 579bab1fe2..c71f92747f 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -32,6 +32,13 @@ def test(method, input, output, *args):
test('capitalize', u' hello ', u' hello ')
test('capitalize', u'hello ', u'Hello ')
+test('count', u'aaa', 3, u'a')
+test('count', u'aaa', 0, u'b')
+test('count', 'aaa', 3, u'a')
+test('count', 'aaa', 0, u'b')
+test('count', u'aaa', 3, 'a')
+test('count', u'aaa', 0, 'b')
+
test('title', u' hello ', u' Hello ')
test('title', u'hello ', u'Hello ')
test('title', u"fOrMaT thIs aS titLe String", u'Format This As Title String')