[Web-SIG] possible bug in cgi

Stephan Diehl stephan at transvection.de
Sun Nov 16 14:51:09 CET 2008


this is probably not the right place to ask, but I found some irritating
behaviour with the cgi module and are unsure if it's a bug (seen on
python2.5 and python2.6)
The problem is this:
>>> import cgi
>>> cgi.FieldStorage(environ={'QUERY_STRING':u'a=b'})
FieldStorage(None, None, [MiniFieldStorage('a\x00', '\x00b\x00')])
>>> cgi.FieldStorage(environ={'QUERY_STRING':'a=b'})
FieldStorage(None, None, [MiniFieldStorage('a', 'b')])

When creating a FieldStorage with an environment that contains a unicode
'QUERY_STRING' value, garbage is returned.
The ultimate problem seems to be, that the QUERY_STRING is converted to
a cStringIO object which holds only the memory representation of unicode
strings.

Regards, Stephan


More information about the Web-SIG mailing list