[Tutor] Untainting CGI parameters

Jan Eden lists at janeden.org
Thu Aug 11 11:43:17 CEST 2005


Hi Alan,

Alan G wrote on 11.08.2005:

>> I will combine Kent's and your suggestion, because he included a 
>> check for an AttributeError:
>>
>
>OK, as a slightly more perl-ish solution to the no Attribute problem
>you could also do this:
>
>try:
>    type = re.search('\w+', parameters['type'].value).group() or 
>'page'
>except KeyError:
>    type = 'page'
>
Are you sure?

>>> a = 'abcd'
>>> import re
>>> type = re.search('\d+',a).group() or 'page'
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'NoneType' object has no attribute 'group'

If the search does not succeed, the returned object has the value None, which has no attribute group.

Thanks,

Jan
-- 
There are two major products that come out of Berkeley: LSD and UNIX. We don't believe this to be a coincidence. - Jeremy S. Anderson


More information about the Tutor mailing list