Kaydet (Commit) a9858559 authored tarafından Guido van Rossum's avatar Guido van Rossum

Backport 1.56 and 1.68 from trunk:

1.56:
Apply diff3.txt from SF patch http://www.python.org/sf/536241

If a str or unicode method returns the original object,
make sure that for str and unicode subclasses the original
will not be returned.

This should prevent SF bug http://www.python.org/sf/460020
from reappearing.

1.68:
Fix SF bug 599128, submitted by Inyeol Lee: .replace() would do the
wrong thing for a unicode subclass when there were zero string
replacements.  The example given in the SF bug report was only one way
to trigger this; replacing a string of length >= 2 that's not found is
another.  The code would actually write outside allocated memory if
replacement string was longer than the search string.
üst 1c4a4576
......@@ -50,6 +50,25 @@ def test(method, input, output, *args):
exc = sys.exc_info()[:2]
else:
exc = None
if value == output and type(value) is type(output):
# if the original is returned make sure that
# this doesn't happen with subclasses
if value is input:
class usub(unicode):
def __repr__(self):
return 'usub(%r)' % unicode.__repr__(self)
input = usub(input)
try:
f = getattr(input, method)
value = apply(f, args)
except:
value = sys.exc_type
exc = sys.exc_info()[:2]
if value is input:
if verbose:
print 'no'
print '*',f, `input`, `output`, `value`
return
if value != output or type(value) is not type(output):
if verbose:
print 'no'
......@@ -186,6 +205,8 @@ test('replace', u'one!two!three!', u'one!two!three!', u'!', u'@', 0)
test('replace', u'one!two!three!', u'one@two@three@', u'!', u'@')
test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@')
test('replace', u'one!two!three!', u'one!two!three!', u'x', u'@', 2)
test('replace', u'abc', u'abc', u'ab', u'--', 0)
test('replace', u'abc', u'abc', u'xy', u'--')
test('startswith', u'hello', 1, u'he')
test('startswith', u'hello', 1, u'hello')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment