Thanks I was looking for a way around "escaping the escape" 
This what I settled with was this:

I use xml formatting for the other chars that need escaping (plus I pulled
one out of my a** for the backslash). I use two subs for this :

sub comment_format($){
my $var =shift;
$var =~ s/\"/"/g;
$var =~ s/\'/'/g;
$var =~ s/</&#60;/g;
$var =~ s/>/&#62;/g;
$var =~ s/\\/&#92;/g; #<- made up 92 is from the ASCII chart
return $var;
}

sub comment_unformat($){
my $var =shift;
$var =~ s/&#34;/\"/g;
$var =~ s/&#39;/\'/g;
$var =~ s/&#60;/</g;
$var =~ s/&#62;/>/g;
$var =~ s/&#92;/\\/g;
return $var;
}

To me, this seems logical. 
That way I only need to call the modules when the user submits and when I
print to the html page. The database information could look ugly tho but why
else would you need to design an interface ?






 
-----Original Message-----
0From: Steven Lembark [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 13, 2002 11:59 AM
To: [EMAIL PROTECTED]
Subject: Re: Backslashes




-- [EMAIL PROTECTED]

> Does anybody have a way to deal with user input containing a '\' from a
> cgi form into a mysql database?
> Or do I have to  do regex to escape user input, escape the database input
> and escape the database out  for every db query or insert ?
>
> Not a complaint but just looking for a better way.


Given that MySQL has to interpret the strings, there isn't
any way to insulate yourself at the Perl level (e.g., by
using single-quotes). Short of treating the data as blobs,
you're stuck escaping them for MySQL.

--
Steven Lembark                               2930 W. Palmer
Workhorse Computing                       Chicago, IL 60647
                                            +1 800 762 1582

Reply via email to