Skip Menu |

This queue is for tickets about the CGI-FormBuilder CPAN distribution.

Report information
The Basics
Id: 40148
Status: resolved
Priority: 0/
Queue: CGI-FormBuilder

People
Owner: Nobody in particular
Requestors: ansgar [...] 2008.43-1.org
Cc:
AdminCc:

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



Subject: Required fields cannot have value "0"
Date: Sat, 18 Oct 2008 13:27:19 +0200
To: bug-CGI-FormBuilder [...] rt.cpan.org
From: Ansgar Burchardt <ansgar [...] 2008.43-1.org>
Hi, Required fields cannot take the value "0". This is annoying for fields that require a number which might be 0. The problem can be reproduced like this: my $form = CGI::FormBuilder->new; $form->field(name => 'foo', required => 1, value => "0"); $form->validate; print $form->render; It says the 'foo' field has an invalid value, setting it to "1" makes FormBuilder accept the form. It would be nice if this could be fixed in the next release. Regards, Ansgar Burchardt -- PGP: 1024D/595FAD19 739E 2D09 0969 BEA9 9797 B055 DDB0 2FF7 595F AD19
From: data [...] cpan.org
On Sat Oct 18 07:27:47 2008, ansgar@2008.43-1.org wrote: Show quoted text
> my $form = CGI::FormBuilder->new; > $form->field(name => 'foo', required => 1, value => "0"); > > $form->validate; > print $form->render; > > It says the 'foo' field has an invalid value, setting it to "1" makes > FormBuilder accept the form.
The attached patch should fix it imho.
Subject: formbuilder.patch
diff --git a/lib/CGI/FormBuilder/Field.pm b/lib/CGI/FormBuilder/Field.pm index 2c68aae..ba5d449 100644 --- a/lib/CGI/FormBuilder/Field.pm +++ b/lib/CGI/FormBuilder/Field.pm @@ -736,9 +736,14 @@ sub validate () { belch "Validation string '$pattern' may be a typo of a builtin pattern" if ($pattern =~ /^[A-Z]+$/); # must reference to prevent serious problem if $value = "'; system 'rm -f /'; '" - debug 2, "$field: '$value' $pattern ? 1 : 0"; - unless (eval qq(\$value $pattern ? 1 : 0)) { - $thisfail = ++$bad; + if($pattern) { + debug 2, "$field: '$value' $pattern ? 1 : 0"; + unless (eval qq(\$value $pattern ? 1 : 0)) { + $thisfail = ++$bad; + } + } else { + debug 2, "$field: '$value' is defined?"; + $thisfail = ++$bad unless(defined($value)); } belch "Literal code eval error in validate: $@" if $@; }