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