in reply to Re: CGI fails to urlencode & chars in outbound url's
in thread CGI fails to urlencode & chars in outbound url's

You also may use CGI.pm's own escape function:

This is probably irrelevant to this discussion. The a() function is being used, which already escapes its arguments. Or at least CGI.pm version 2.752 does.

2;0 juerd@ouranos:~$ perl -MCGI=a -le'print a({ -href => "&&&" }, "asd +f")' <a href="&amp;&amp;&amp;">asdf</a>

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

Replies are listed 'Best First'.
Re: Re: Re: CGI fails to urlencode & chars in outbound url's
by projekt21 (Friar) on Jun 12, 2002 at 16:27 UTC

    But that's exactly what nobody wants, as the & of &amp; is treated as parameter delimiter.

    #!/usr/bin/perl -w use strict; use CGI; my $q = new CGI; print $q->header; print "<pre>\n"; print $_, "=", $q->param($_), "\n" for $q->param; print "\n</pre>\n";
    prints
    foo=bar amp= baz=
    for
    http://electra.igd.fhg.de/cgi-bin/test3.pl?foo=bar&amp;baz
    but it should print
    foo=bar&baz
    You need to use CGI::escape or URI::Escape but not CGI::escapeHTML.

    Update: Just for completeness: a() calls CGI::Util::make_attributes on each attribute, the latter calls CGI::Util::simple_escape for escaping ("&"->"&amp;" and some others). CGI::Util::escape does something different (see my last post).

    alex pleiner <alex@zeitform.de>
    zeitform Internet Dienste