[Python-bugs-list] [ python-Bugs-561796 ] string.find causes lazy error
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 29 May 2002 04:33:58 -0700
Bugs item #561796, was opened at 2002-05-29 03:33
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=561796&group_id=5470
Category: Python Library
>Group: Python 2.2.1 candidate
>Status: Open
Resolution: Fixed
Priority: 5
Submitted By: Greg Jones (morngnstar)
Assigned to: M.-A. Lemburg (lemburg)
Summary: string.find causes lazy error
Initial Comment:
To repro:
1. start an interactive session (don't use IDLE, use the
command line interface)
2. import string
3. string.split(u'test\0630', 'fail')
[u'test\0630']
4. string.find('test\xCC', u'test')
expect 0
actual -1
Possibly my expectation is incorrect. Technically,
since the default encoding is ASCII, and the code value
0xCC has no meaning in ASCII, this code point can't be
translated to Unicode. It would be unwarranted to
assume that the correct translation was the same code
value. So in general, the find cannot determine the result.
However, it seems the proper behavior would then be to
throw an exception. It cannot be determined that u'test'
is in the string, but it also cannot be determined that it
is not. So it is not correct to return -1 indicating the
latter.
Also, continue entering commands:
5. string.split(u'test\0630', 'fail')
expect [u'test\0630']
actual UnicodeError: ASCII decoding error: ordinal not in
range(128)
Note (5) is the same as (3) and is a command that
should not depend on state, but the results are different.
What is happening is that (4) actually generates the
UnicodeError, but the exception-throwing mechanism is
not invoked and interpretation continues. When (5) is
executed, the error status is still set. It is checked, and
the exception is now thrown.
I have explored the code that causes this bug deeply
and am working on a fix.
----------------------------------------------------------------------
Comment By: M.-A. Lemburg (lemburg)
Date: 2002-05-29 11:33
Message:
Logged In: YES
user_id=38388
Just checked in a fix in CVS.
----------------------------------------------------------------------
Comment By: M.-A. Lemburg (lemburg)
Date: 2002-05-29 10:33
Message:
Logged In: YES
user_id=38388
I can't reproduce 3./5. in the latest CVS version, but I
do get strange output from running:
>>> string.find('test\xCC', u'test')
-1
>>> string.find('test\xCC', u'test')
UnicodeError: ASCII decoding error: ordinal not in range(128)
>>> string.find('test\xCC', u'test')
-1
>>> string.find('test\xCC', u'test')
UnicodeError: ASCII decoding error: ordinal not in range(128)
>>> string.find('test\xCC', u'test')
-1
>>> string.find('test\xCC', u'test')
UnicodeError: ASCII decoding error: ordinal not in range(128)
>>> string.find('test\xCC', u'test')
-1
>>> string.find('test\xCC', u'test')
UnicodeError: ASCII decoding error: ordinal not in range(128)
>>> string.find('test\xCC', u'test')
-1
Looks like an exception is set but not properly
propogated back the caller.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=561796&group_id=5470