wrote:
> Hello,
>
> I use CGI.pm to parse forms, and I am running into issues with
certain
> special characters.
>
> Say I have a form element, with a value of "Mom's House". It is a
> hidden input, passed in from a previous page, so the HTML is
something
> like this:
>
> <INPUT TYPE="hidden" NAME="location" VALUE="Mom's House">
print hidden(-name=>'location', -value=>"Mom's House");
Should work fine if you use CGI.pm like this.
>
> I was given to understand that, for ' " > < and &, you need to use
the
> encoded value to denote the character when it appears in a tag. I
know
> this is the case for normal XML files, and the parsers take care of
it.
> However, CGI.pm's param() function does NOT seem to be interpreting
> the special characters. In the CGI script that processes this form,
I
> would have:
>
> $location = param('location');
>
> and $location would be: "Mom's House" While I could, in this
> instance, simply NOT encode the apostrophe and it would probably
work,
> if it were a double quote, I know it would break it. Any ideas?
> Thanks!
>
>From CGI.pm home page: http://stein.cshl.org/WWW/software/CGI/
<quote>
AUTOESCAPING HTML
By default, all HTML that are emitted by the form-generating functions
are passed through a function called escapeHTML():
$escaped_string = escapeHTML("unescaped string");
Provided that you have specified a character set of ISO-8859-1 (the
default), the standard HTML escaping rules will be used. The "<"
character becomes "<", ">" becomes ">", "&" becomes "&", and
the quote character becomes """. In addition, the hexadecimal 0x8b
and 0x9b characters, which many windows-based browsers interpret as the
left and right angle-bracket characters, are replaced by their numeric
HTML entities ("‹" and ""). If you manually change the
charset, either by calling the charset() method explicitly or by
passing a -charset argument to header(), then all characters will be
replaced by their numeric entities, since CGI.pm has no lookup table
for all the possible encodings.
Autoescaping does not apply to other HTML-generating functions, such as
h1(). You should call escapeHTML() yourself on any data that is passed
in from the outside, such as nasty text that people may enter into
guestbooks.
To change the character set, use charset(). To turn autoescaping off
completely, use autoescape():
$charset = charset([$charset]); # Get or set the current character
set.
$flag = autoEscape([$flag]); # Get or set the value of the
autoescape flag.
</quote>
Hope this helps.
wana