Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

?& in query string causes errors

by lpoht (Sexton)
on Jul 31, 2003 at 19:26 UTC ( [id://279735]=perlquestion: print w/replies, xml ) Need Help??

lpoht has asked for the wisdom of the Perl Monks concerning the following question:

I'm running ActiveState Perl 5.6.1 on a Windows 2000 server, and am having the problem that when I access a script from my browser using a url such as "choosecat.cgi?&category=1", I get the following error
Use of uninitialized value in hash element at C:/Perl/lib/CGI.pm line 549
displayed at the bottom of the page. I imagine that the error prints on the page due to my use of HTML::Template. If I access the script without the ampersand immediately following the question mark, the error disappears. I used PPM to install the latest version of CGI to no avail. Does anyone know what is going on or of another site I can refer to? Thanks

Replies are listed 'Best First'.
Re: ?& in query string causes errors
by fglock (Vicar) on Jul 31, 2003 at 19:34 UTC

    That's a problem with the CGI.pm that comes with AS 5.6.1. Try to upgrade it from CPAN.

    In AS 5.8.0, it reads:

    ($param,$value) = split('=',$_,2); next unless defined $param; # skip - no error ! next if $NO_UNDEF_PARAMS and not defined $value;

    While in AS 5.6.1 it reads:

    ($param,$value) = split('=',$_,2); $value = '' unless defined $value; $param = unescape($param); # "uninitialized" error !
Re: ?& in query string causes errors
by skyknight (Hermit) on Jul 31, 2003 at 19:31 UTC

    You're getting a blank name/value pair. The general format of an HTTP get request is

    url?name1=value1&name2=value2&name3=value3

    CGI.pm is probably first splitting the query string on & chars, and then subsequently splitting those chunks on = chars, and associating each of those two pieces as the name and value of a key in a hash. If you put an & char at the start of the query string, CGI.pm is going to get confused, as it'll have an empty string that it tries to split in an = char, and then it will try to stick those values (that it didn't get) into a hash.

Re: ?& in query string causes errors
by sgifford (Prior) on Jul 31, 2003 at 19:35 UTC
    What version of CGI.pm are you using? I submitted a bug report and patch for this about a year ago, and I believe it's fixed in the latest version.
Re: ?& in query string causes errors
by cleverett (Friar) on Jul 31, 2003 at 19:30 UTC
    Heh, so don't do that.

    is there a particular reason you can't use a URL like the following?

    choosecat.cgi?category=1
      I'm not trying to do that. I discovered this problem while testing the pages. I will go ahead and try a CPAN upgrade. Thanks, everyone, for your input.
Re: ?& in query string causes errors
by Cine (Friar) on Jul 31, 2003 at 20:00 UTC
    Just a minor thing: In the newer html-standards, ampersans in links must be encoded as &

    T I M T O W T D I

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://279735]
Approved by blue_cowdawg
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (1)
As of 2024-04-24 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found