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: 93006
Status: open
Priority: 0/
Queue: Data-FormValidator

People
Owner: Nobody in particular
Requestors: cpan [...] opperschaap.net
Cc:
AdminCc:

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



Subject: Array refs cannot be checked correctly.
#!/usr/bin/perl use Test::More; use Data::FormValidator; { my $profile = { required => 'hash_ref', constraint_methods => { hash_ref => sub { my ($dv, $val) = @_; if (ref $val eq 'HASH') { return 1; } return 0; }, }, }; my $result = Data::FormValidator->check({hash_ref => {hash => 'ref'}}, $profile,); ok($result->success, "hash ref is valid"); } { my $profile = { required => 'array_ref', constraint_methods => { array_ref => sub { my ($dv, $val) = @_; if (ref $val eq 'ARRAY') { return 1; } return 0; }, }, }; my $result = Data::FormValidator->check({array_ref => [qw(array ref)]}, $profile,); ok($result->success, "Array ref is valid"); } done_testing;
Subject: Re: [rt.cpan.org #93006] Array refs cannot be checked correctly.
Date: Thu, 13 Feb 2014 06:47:30 -0800
To: "https://launchpad.net/~wesleys via RT" <bug-Data-FormValidator [...] rt.cpan.org>
From: Mark Stosberg <mark [...] stosberg.com>
I believe the handling of inputs with multiple values is documented. Each one is sent through a constraint individually. Mark
On Thu Feb 13 09:47:39 2014, mark@stosberg.com wrote: Show quoted text
> > I believe the handling of inputs with multiple values is documented. > > Each one is sent through a constraint individually. > > Mark
I couldn't find it in the docs. I made a patch that keeps the current behavior and allows checking array refs as well.
Subject: no_redef.patch
Thu Feb 13 15:57:18 CET 2014 wesley@schwengle.net * no_deref Do not allow array refs to be dereferenced for constraint checking. diff -rN -u old-dfv/lib/Data/FormValidator/Results.pm new-dfv/lib/Data/FormValidator/Results.pm --- old-dfv/lib/Data/FormValidator/Results.pm 2014-02-13 16:46:39.461255354 +0100 +++ new-dfv/lib/Data/FormValidator/Results.pm 2014-02-13 16:46:39.465255354 +0100 @@ -367,10 +367,10 @@ $untaint_all = 1; } - $self->_check_constraints($private_constraints,\%valid,$untaint_all,\%untaint_hash); + $self->_check_constraints($private_constraints,\%valid,$untaint_all,\%untaint_hash, 0, $profile->{no_deref}); my $force_method_p = 1; - $self->_check_constraints($private_constraint_methods,\%valid,$untaint_all,\%untaint_hash, $force_method_p); + $self->_check_constraints($private_constraint_methods,\%valid,$untaint_all,\%untaint_hash, $force_method_p, $profile->{no_deref}); # add back in missing optional fields from the data hash if we need to for my $field ( keys %data ) { @@ -1207,7 +1207,8 @@ $valid, $untaint_all, $untaint_href, - $force_method_p) = @_; + $force_method_p, + $no_deref) = @_; while ( my ($field,$constraint_list) = each %$constraint_href ) { next unless exists $valid->{$field}; @@ -1230,7 +1231,7 @@ my $c = $self->_constraint_hash_build($constraint_spec,$untaint_this, $force_method_p); $c->{is_method} = 1 if $force_method_p; - my $is_value_list = 1 if (ref $valid->{$field} eq 'ARRAY'); + my $is_value_list = 1 if (ref $valid->{$field} eq 'ARRAY') && !$no_deref; my %param_data = ( $self->_get_input_as_hash($self->get_input_data) , %$valid ); if ($is_value_list) { for (my $i = 0; $i < scalar @{ $valid->{$field}} ; $i++) { diff -rN -u old-dfv/lib/Data/FormValidator.pm new-dfv/lib/Data/FormValidator.pm --- old-dfv/lib/Data/FormValidator.pm 2014-02-13 16:46:39.461255354 +0100 +++ new-dfv/lib/Data/FormValidator.pm 2014-02-13 16:46:39.469255354 +0100 @@ -476,6 +476,12 @@ interdependent fields. The keys are arbitrary names that you create and the values are references to arrays of the field names in each group. +=head2 no_deref + + no_deref => 1, # or 0 + +This is a boolean value to allow dereferencing of array refs. Defaults to 0. + =head2 allow_unknown allow_unknown => 0, # or 1 @@ -951,6 +957,7 @@ untaint_regexp_map debug allow_unknown + no_deref /); # If any of the keys in the profile are not listed as
The patch didn't include the test file. #!/usr/bin/perl use Test::More; use Data::FormValidator; { my $profile = { required => 'array_ref', constraint_methods => { array_ref => sub { my ($dv, $val) = @_; if (ref $val eq 'ARRAY') { return 1; } return 0; }, }, no_deref => 1, }; my $result = Data::FormValidator->check({array_ref => [qw(array ref)]}, $profile,); ok($result->success, "Array ref is valid"); } done_testing; On Thu Feb 13 10:52:08 2014, https://launchpad.net/~wesleys wrote: Show quoted text
> On Thu Feb 13 09:47:39 2014, mark@stosberg.com wrote:
> > > > I believe the handling of inputs with multiple values is documented. > > > > Each one is sent through a constraint individually. > > > > Mark
> > I couldn't find it in the docs. > I made a patch that keeps the current behavior and allows checking > array refs as well.
Subject: Re: [rt.cpan.org #93006] Array refs cannot be checked correctly.
Date: Thu, 13 Feb 2014 08:13:25 -0800
To: "https://launchpad.net/~wesleys via RT" <bug-Data-FormValidator [...] rt.cpan.org>
From: Mark Stosberg <mark [...] stosberg.com>
I'm not interested in this patch at this time. I would consider it further if several other people expressed interest in it, but this is the first interest expressed that I can recall in several years. I'm also not fond of the name, which is not particularly clear, and defaults to a confusing double negative of "no dereference is false". You have the option to write a custom constraint if you prefer to validate an input as an array instead of distinct inputs. Mark On Thu, Feb 13, 2014, at 07:54 AM, https://launchpad.net/~wesleys via RT wrote: Show quoted text
> Queue: Data-FormValidator > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=93006 > > > > The patch didn't include the test file. > > #!/usr/bin/perl > > use Test::More; > use Data::FormValidator; > > { > my $profile = { > required => 'array_ref', > constraint_methods => { > array_ref => sub { > my ($dv, $val) = @_; > if (ref $val eq 'ARRAY') { > return 1; > } > return 0; > }, > }, > no_deref => 1, > }; > my $result = Data::FormValidator->check({array_ref => [qw(array > ref)]}, $profile,); > ok($result->success, "Array ref is valid"); > } > > done_testing; > > > > > On Thu Feb 13 10:52:08 2014, https://launchpad.net/~wesleys wrote:
> > On Thu Feb 13 09:47:39 2014, mark@stosberg.com wrote:
> > > > > > I believe the handling of inputs with multiple values is documented. > > > > > > Each one is sent through a constraint individually. > > > > > > Mark
> > > > I couldn't find it in the docs. > > I made a patch that keeps the current behavior and allows checking > > array refs as well.
> > >
From: site-bitcard.org [...] hatsuseno.org
On Thu Feb 13 11:13:34 2014, mark@stosberg.com wrote: Show quoted text
> I'm not interested in this patch at this time. > > I would consider it further if several other people expressed interest
I've run across this 'issue' of array unpacking as well. I can make do with the current way D:FV handles them, but I have to put extra guards in my functions that pick up on the arrayref-ness of parameters, because technically I cannot trust the input *not* to be an arrayref of valid values. The proposed behavior where array-unpacking is configurable would help me keep my code clean(er).