Subject: | hidden() does not assign the given value to the named element |
Date: | Fri, 1 Mar 2013 14:51:36 -0600 |
To: | bug-CGI [...] rt.cpan.org |
From: | Dmitry Konopatski <konop039 [...] umn.edu> |
#!/usr/bin/perl
# bug-CGI [at] rt.cpan.org
=pod
Hi,
Using the following scenario I am trying to create a hidden input "weather"
with an explicitly assigned value of "exciting". The problem is that my
input will be assigned a different value of "dull" which comes in the body
of the HTTP request.
I have not had a chance to come up with a patch, but I am sending you a
test script that would allow you to reproduce the issue for the recent
versions of CGI.pm
Thanks,
Dmitry Konopatski
=cut
BEGIN {
use strict;
use warnings;
use lib qw(lib ../lib);
use Test::More;
}
use CGI;
my ($name, $val, $newval) = ("weather", "dull", "exciting");
my $q = CGI->new("$name=$val");
ok(($a = $q->hidden($name, $newval)) !~ /\Q$newval\E/i, $a);
ok(($a = $q->hidden($name, $newval)) =~ /\Q$val\E/i, $a);
ok(($b = $q->hidden(-name => $name, -default => $newval)) !~
/\Q$newval\E/i, $b);
ok(($b = $q->hidden(-name => $name, -default => $newval)) =~ /\Q$val\E/i,
$b);
ok($a eq $b, "HTML is the same");
ok(($a = $q->hidden(-name => $name, -default => $q->param("weather",
$newval))) =~ /\Q$newval\E/i, "Workaround 1");
ok(($b = $q->input({type => "hidden", name => $name, value => $newval})) =~
/\Q$newval\E/i, "Workaround 2");
done_testing();