Python's CGI and Javascripts uriEncode: A disconnect.

Elf M. Sternberg elf at drizzle.com
Tue Jul 1 14:39:04 EDT 2003


It's all Netscape's fault.

RFC 2396 (URI Specifications) specifies that a space shall be encoded
using %20 and the plus symbol is always safe.  Netscape (and possibly 
even earlier browsers like Mosaic) used the plus symbol '+' as a
substitute for the space in the last part of the URI, arguments to the
object referenced (you know, all the stuff after the question mark in
a URL).

The ECMA-262 "Javascript" standard now supported by both Netscape and
Internet Explorer honor RFC 2396, translating spaces into their hex
equivalent %20 and leaving pluses alone.

The Python library cgi.FieldStorage decodes it backwards, expecting
pluses to be spaces and %2b to represent pluses.  This behavior is
present even in python 2.2, and arguably helps support older browsers.
But when web applications are heavily javascript-dependent, this can
cause major headaches.  

Other than override cgi.FieldStorage's parse_qsl, is there anyway to
fix this disconnect?

        Elf




More information about the Python-list mailing list