in reply to HTML::ENTITIES for URL encoding
Sounds like you're trying to protect against XSS attacks, which is a Good Thing. But I think you may be overcomplicating your solution. Try calling the following with the URL test.cgi?link=http://www.google.com%22%3E%3Cscript%3Ealert%28%27Bang!%27%29%3C/script%3E (i.e. "test.cgi?link=http://www.google.com"><script>alert('Bang!')</script>") and look at the resulting HTML.
use CGI; my $cgi=CGI->new; print $cgi->header; print $cgi->start_html; my $link=$cgi->param("link"); print "<a href=\"$link\">Link</a><br/>\n"; # BAD! print "<a href=\"".$cgi->escapeHTML($link) # Good ."\">Link</a><br/>\n"; print $cgi->a({href=>$link},"Link"), $cgi->br; # Better print $cgi->end_html;
CGI's escapeHTML is just a shortcut to HTML::Entities's encode_entities. Also, I don't understand why you need to escape param names (at least I think that's what you're trying to do?), unless at some point in your script you are dumping all of your params somewhere? If so, the advice is simple: don't do that!
|
|---|