Re: About "How do I decode or create those %-encodings on the web?"
[email protected] (Peter Valdemar Mørch) Mon, 28 Jun 2010 01:57:31 -0700 (PDT)
| Newsgroups | perl.perlfaq.workers |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <[email protected]> |
On Jun 27, 4:27=A0am, [email protected] (brian d foy) wrote: > Patches welcome :) CC: Lincoln D. Stein, author of CGI.pm Yeah, as soon as I hit "Send" I realized that was a very probable repsonse :-) Ok, so here goes. Also available at http://pastebin.com/bPRq0N= sj in case Google Groups mangles or does line wrapping: --- orig.CGI.pm 2010-01-29 15:41:54.000000000 +0100 +++ CGI.pm 2010-06-28 08:56:49.000000000 +0200 @@ -255,6 +255,7 @@ ':html' =3D> [qw/:html2 :html3 :html4 :netscape/], ':standard' =3D> [qw/:html2 :html3 :html4 :form :cgi/], ':push' =3D> [qw/multipart_init multipart_start multipart_end multipart_final/], + ':escape' =3D> [qw/escape unescape/], ':all' =3D> [qw/:html2 :html3 :netscape :form :cgi :internal :html4/] ); @@ -4878,6 +4879,10 @@ Import all HTML-generating shortcuts (i.e. 'html2', 'html3', 'html4' and 'netscape') +=3Ditem B<:escape> + +Import the escape and unescape methods + =3Ditem B<:standard> Import "standard" features, 'html2', 'html3', 'html4', 'form' and 'cgi'. @@ -5698,6 +5703,20 @@ ), hr; +=3Dhead2 ESCAPING/ENCODING AND UNESCAPING/DECODING URL STRINGS + +URL parameters are encoded in what is also known as Percent-encoding +L<http://en.wikipedia.org/wiki/Percent-encoding> + + use CGI ':escape'; + my $string =3D "Hello World"; + my $escaped =3D escape($string); + print $escaped, "\n"; + die "How could unescape(escape($string)) ne $string" + unless unescape($escaped) eq $string; + +prints out "Hello%20World" + =3Dhead2 PROVIDING ARGUMENTS TO HTML SHORTCUTS The HTML methods will accept zero, one or multiple arguments. If you Peter