develooper Front page | perl.beginners | Postings from March 2002

Re: unallowed chars

Thread Previous | Thread Next
From:
John W. Krahn
Date:
March 29, 2002 14:10
Subject:
Re: unallowed chars
Message ID:
3CA4E629.632266DE@acm.org
John wrote:
> 
> The incoming e-mail form variables from my web page are vetted through
> various tests before they're processed. The first thing I do is to translate
> all "<, >, {, }, [, ]" characters to either "(" or ")", as appropriate. My
> theory is that I don't want any HTML tags being taken in, and will gladly
> suffer whatever small degradation which might occur to someone's prose style
> as a consequence. <g>
> 
>         $user_body =~ tr/<->/(-)/;
>         $user_body =~ tr/{-}/(-)/;
>         $user_body =~ tr/[-]/(-)/;

You do realize that using a hyphen (-) in a character class creates a
range of characters.  tr/<->/(-)/ changes '<' to '(', '=' to '-' and '>'
to ')'.  tr/{-}/(-)/ changes '{' to '(', '|' to '-' and '}' to ')'. 
tr/[-]/(-)/ changes '[' to '(', '\' to '-' and ']' to ')'.


John
-- 
use Perl;
program
fulfillment

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About