Re: cgi.py

N.G.Smith (ngs@ukc.ac.uk)
Wed, 22 Jun 94 08:58:21 BST

In article <9406211529.AA00645@acdc.eeel.nist.gov> mclay@eeel.nist.gov (Michael McLay) writes:
>Thanks for the bug report. The fix also eliminated some ugly code. I've
>incorporated your suggestion and attached the update.
>
>Michael
>
> nv = string.splitfields(name_value, '=')
> name = nv[0]
> value = urllib.unquote(nv[1])
> if len(value):
> if self.t.has_key (name):
> self.t[name].append(value)
> else:
> self.t[name] = [value]

I do not know whether it is legal to have a query string with the
right hand side of the `=' empty, but if it is, this code will still
break. My fix went something like this...

nv = string.splitfields(name_value, '=')
if len(nv) == 2:
name = nv[0]
value = urllib.unquote(nv[1])
if self.t.has_key (name):
self.t[name].append(value)
else:
self.t[name] = [value]

But on second thoughts, this will simply not set the variable if the
rhs is empty, whereas what it perhaps should do is set it to an empty
string. Can anyone with more python experience than me offer a good
solution?

Neil.