On Sunday, 29 April 2012 19:56:21 UTC-5, Anthony wrote:
>
> On Sunday, April 29, 2012 7:54:11 PM UTC-4, Massimo Di Pierro wrote:
>>
>> I often run into this problem:
>>
>> def index():
>>       record=db.tablename(request.args(0))  or redirect(URL('error'))
>>
>> which assumes request.args(0) is integer or missing. If not it issues a 
>> ticket.
>>
>
> If request.args(0) is not an integer or missing, doesn't 
> db.tablename(request.args(0)) simply return None -- in which case, no 
> ticket should be issued? 
>

If missing returns None but does not check if an integer. depending on how 
it is used, it may cause a ticket.

 

> Also, you can already do request.args(0, default=0) if you want a 0 
> instead of None when request.args is empty, no?
>


This is be a good idea. There are two parameters to specify: default and 
type. How about?


request.args(0,default=0, cast=int, requires=list_of_validators, 
url_onerror=URL(...)) 

 
>
>> In trunk there is a new request.intargs which allows
>>
>> def index():
>>       record=db.tablename(request.intargs(0,default=0)) or 
>> redirect(URL('error'))
>>
>>
> Another option might be:
>
> request.args(0, assert_int=True, ...)
>
> Anthony
>
>

Reply via email to