Check "Evil" Characters 
Author Message
 Check "Evil" Characters

I am writing a python script for checking the
"evil characters" in the submitted associative
arrays from a HTML form using POST method. In
Perl,  the central part of the script is as follows.

                ...#report evil characters

Quote:
}

In other words, the only acceptable characters are:
0-9a-zA-Z
\r\t\n\f

The script should report "evil characters" if there
are any other characters in the submitted string.

I would appreciate it if somebody could tell me how to
do that (the equivalence of the above Perl statement)
in Python.

Please send me email in addition to posting to this
newsgroup. Many thanks in advance!

Ganghuai Wang
------
http://www.*-*-*.com/ .{*filter*}ia.edu/~gw2p/



Sun, 09 Aug 1998 03:00:00 GMT  
 Check "Evil" Characters

Quote:

>I am writing a Python script for checking the
>"evil characters" in the submitted associative
>arrays from a HTML form using POST method. In
>Perl,  the central part of the script is as follows.

>                ...#report evil characters
>}

>In other words, the only acceptable characters are:
>0-9a-zA-Z
>\r\t\n\f


import string

# test for evil characters in s
for c in s:
    if not c in good:
       raise "hell"
# then again, the Perl is much more compact ;)

#filter out evil characters efficiently
filterlist = [None] * 256
for c in good:
    filterlist[ord(c)] = 1
def filterchar(c):
    return filterlist[ord(c)]
def filterstring(str):
    return filter(filterchar, str)

Hope that helps...  Aaron Watters
====
UN peacekeepers are not allowed to shoot at anyone unless they are under
attack so severely that they're probably already dead.  -- PJ O'Rourke.



Mon, 10 Aug 1998 03:00:00 GMT  
 Check "Evil" Characters

Quote:

> >I am writing a Python script for checking the
> >"evil characters" in the submitted associative
> >arrays from a HTML form using POST method. In
> >Perl,  the central part of the script is as follows.

> >                ...#report evil characters
> >}

> >In other words, the only acceptable characters are:
> >0-9a-zA-Z
> >\r\t\n\f

> import string

> # test for evil characters in s
> for c in s:
>     if not c in good:
>        raise "hell"
> # then again, the Perl is much more compact ;)

> #filter out evil characters efficiently
> filterlist = [None] * 256
> for c in good:
>     filterlist[ord(c)] = 1
> def filterchar(c):
>     return filterlist[ord(c)]
> def filterstring(str):
>     return filter(filterchar, str)

> Hope that helps...  Aaron Watters

I haven't measured this, but I wouldn't be surprised if the following
is faster:

import string, regex
# note - must come first in the character set

# test for evil characters in s
if good_re.match(s) < 0:
    raise 'hell'


   <URL:http://www.cwi.nl/~sjoerd/>



Mon, 10 Aug 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Finding "Evil" Characters

2. Check Characters "cc"

3. Checking strings for "bad" characters

4. '"""' and linefeed characters

5. string.join(["Tk 4.2p2", "Python 1.4", "Win32", "free"], "for")

6. Characters "?", "?", "ΓΌ" shown in wrong font

7. Setting "checked" property on menu item

8. "like Current" and static type checking

9. type checking/inferencing for "beginners"

10. Interesting change in "bounds checking"

11. Conditional "checking"

12. "Annoying" subscript checking

 

 
Powered by phpBB® Forum Software