Skip Menu |

This queue is for tickets about the Data-FormValidator CPAN distribution.

Maintainer(s)' notes

This is the bug queue for Data::FormValidator.

Report information
The Basics
Id: 24703
Status: resolved
Priority: 0/
Queue: Data-FormValidator

People
Owner: MARKSTOS [...] cpan.org
Requestors: GTERMARS [...] cpan.org
Cc:
AdminCc:

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



Subject: _arrayify() treats list with empty first value as an empty list
In DFV::Results, "_arrayify()" returns an empty list if it is handed a list which has an undefined first item. Although this works in most cases, in the case of multiple form fields with the same name it can fall down. I'm currently using a form that has multiple "upload" fields, and if the user uploads files in the second, third, etc. field but leaves the first one blank, the -entire- upload is ignored (because _arrayify() treats the list as empty because the first value is undef). I see that MTS filed a wish against List-MoreUtils back in Bug #17230, and in the discussion that followed, Tassilo identified this case as a possible issue and provided a simplified/refactored version of _arrayify(). The attached "dfv-arrayify-simplify.patch" applies that simplification to DFV::Results, while we await possible inclusion of a new "listify()" method in List-MoreUtils. With this patch applied, all of the existing DFV v4.50 tests continue to pass.
Subject: dfv-arrayify-simplify.patch
diff -ru Data-FormValidator-4.50.orig/lib/Data/FormValidator/Results.pm Data-FormValidator-4.50/lib/Data/FormValidator/Results.pm --- Data-FormValidator-4.50.orig/lib/Data/FormValidator/Results.pm 2006-12-04 18:38:14.000000000 -0800 +++ Data-FormValidator-4.50/lib/Data/FormValidator/Results.pm 2007-01-31 13:56:54.530137438 -0800 @@ -841,15 +841,10 @@ # if the input is undefined, return an empty list my $val = shift; defined $val or return (); - - if ( ref $val eq 'ARRAY' ) { - # if it's a reference, return an array unless it points an empty array. -mls - return (defined $val->[0]) ? @$val : (); - } - else { - # if it's a string, return an array unless the string is missing or empty. -mls - return (length $val) ? ($val) : (); - } + # if it's a reference, return an array + return @$val if (ref $val eq 'ARRAY'); + # if it's a string, return an array unless the string is missing or empty + return (length $val) ? ($val) : (); } # apply filter, modifying %valid by reference
RT-Send-CC: paul.blair [...] pobox.com
On Wed Jan 31 17:05:58 2007, GTERMARS wrote: Show quoted text
> In DFV::Results, "_arrayify()" returns an empty list if it is handed a > list which has an undefined first item. Although this works in most > cases, in the case of multiple form fields with the same name it can > fall down. I'm currently using a form that has multiple "upload" > fields, and if the user uploads files in the second, third, etc. field > but leaves the first one blank, the -entire- upload is ignored > (because _arrayify() treats the list as empty because the first value > is undef). > > I see that MTS filed a wish against List-MoreUtils back in Bug #17230, > and in the discussion that followed, Tassilo identified this case as a > possible issue and provided a simplified/refactored version of > _arrayify(). > > The attached "dfv-arrayify-simplify.patch" applies that simplification > to DFV::Results, while we await possible inclusion of a > new "listify()" method in List-MoreUtils. > > With this patch applied, all of the existing DFV v4.50 tests continue > to pass.
This has now been addressed, using a patch and test from Paul Blair, with some further modification. Mostly for Paul, here are some notes on my further refinements: - I merged the tests into t/04_arrayify_undef.t, which was already testing _arrayify. - I used the Perl6::Junction "any()" function to check if any array element is defined. We were already using rountines from there in Data::FormValidator. Stalling this ticket until the next release. Mark
This was released. Mark