Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the CGI CPAN distribution.

Report information
The Basics
Id: 37365
Status: resolved
Worked: 2 min
Priority: 0/
Queue: CGI

People
Owner: LDS [...] cpan.org
Requestors: chris [...] pirazzi.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: BUG $query->Vars tied hash regression: exists() now fails, worked before
Date: Thu, 3 Jul 2008 12:21:20 +0700
To: bug-CGI.pm [...] rt.cpan.org
From: "Chris Pirazzi" <chris [...] pirazzi.net>
CGI.pm version: 3.38 Perl version: v5.8.8 built for i686-linux Linux 2.6.9-67.0.7.ELsmp #1 SMP Sat Mar 15 06:54:55 EDT 2008 i686 i686 i386 GNU/Linux This is something which has broken in the last few months, though I'm not sure exactly which version of CGI caused it. When you use the tied hash returned by $query->Vars, exists() always returns false. It used to return the correct value. There is an EXISTS routine (autoloaded) in CGI.pm but I cannot figure out why it is not used/working. Run the following short script to see the problem: #!/usr/bin/perl use English; use strict; use CGI qw/-oldstyle_urls/; # use '&' in $query->query_string, not ';' use CGI::Util; my $query = new CGI(); my $inparams = {$query->Vars}; # plain hash my $inparams2 = $query->Vars; # tied hash print "Content-Type: text/html\n\n"; foreach my $k (keys %$inparams) { print "[$k] [$inparams->{$k}] [" . exists($inparams->{$k}) . "] [" . exists($inparams2->{$k}) . "]<br>\n"; } Notice how the real hash gives you 1 for exists, but the tied hash gives you 0.
From: todd_lewis [...] unc.edu
Download (untitled) / with headers
text/plain 299b
I can confirm this. 3.37 did not have this bug; 3.38 does. The problem is line 1179 of CGI.pm. The 3.38 code reads: sub EXISTS { exists $_[0]->{$_[1]}; } while it should read like so: sub EXISTS { exists $_[0]->{param}{$_[1]}; } The attached file demonstrates the problem quite nicely.
Download exists_test.pl
text/x-perl 704b
#!/usr/bin/perl -w # exists_test.pl: Test the 'exists' function on the tied hash of CGI parameters. # Invoke like so: # exists_test.pl a=1 b=2 c=3 use strict; use CGI; my %input; CGI::ReadParse(\%input); print CGI::Dump(),"\n"; print join ', ', keys %input, "\n"; for my $k ( keys %input ) { print "Key: '$k', ", (exists $input{$k} ? 'does ' : 'does not '), "exist"; print " (yet it has value '$input{$k}')" if $input{$k}; print ".\n"; print "Deleting \$input{$k}.\n"; delete $input{$k}; print "Key: '$k', ", (exists $input{$k} ? 'does ' : 'does not '), "exist"; print " (yet it has value '$input{$k}')" if $input{$k}; print ".\n"; print "\n"; }
This was broken in version 3.38 only, and is now fixed in version 3.39.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.