Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix dereferencing of single-value arrayrefs. (Dennis Schön)

  • Loading branch information...
commit 8bd3392155210f736c74d2c1d7e193c146899293 1 parent 35ecd1a
Cory Watson authored
Showing with 31 additions and 2 deletions.
  1. +4 −0 Changes
  2. +7 −2 lib/Data/Verifier.pm
  3. +20 −0 t/array.t
View
4 Changes
@@ -1,5 +1,9 @@
Revision history for Data-Verifier
+0.37
+ * Don't dereference ArrayRef values with a single member. (Dennis Schön,
+ RT #60425)
+
0.36
* Don't die by attempting to cram a non-arrayref-ref into an array-ref.
View
9 lib/Data/Verifier.pm
@@ -1,7 +1,7 @@
package Data::Verifier;
use Moose;
-our $VERSION = '0.36';
+our $VERSION = '0.37';
use Data::Verifier::Field;
use Data::Verifier::Filters;
@@ -194,10 +194,13 @@ sub verify {
sub _filter_value {
my ($self, $filters, $values) = @_;
+
+ my $created_ref = 0;
if(ref($filters) ne 'ARRAY') {
$filters = [ $filters ];
}
if(!ref($values)) {
+ $created_ref = 1;
$values = [ $values ];
}
@@ -214,7 +217,7 @@ sub _filter_value {
}
# Return an arrayref if we have multiple values or a scalar if we have one
- scalar(@{ $values }) == 1 ? $values->[0] : $values;
+ return $created_ref ? $values->[0] : $values;
}
__PACKAGE__->meta->make_immutable;
@@ -507,6 +510,8 @@ Stevan Little
George Hartzell
+Dennis Schön
+
=head1 COPYRIGHT & LICENSE
Copyright 2009 Cold Hard Code, LLC
View
20 t/array.t
@@ -13,6 +13,26 @@ use Data::Verifier;
}
);
+ my $results = $verifier->verify({ name => [ 'foo' ] });
+
+ ok($results->success, 'success');
+ cmp_ok($results->valid_count, '==', 1, '1 valid');
+ cmp_ok($results->invalid_count, '==', 0, 'none invalid');
+ cmp_ok($results->missing_count, '==', 0, 'none missing');
+ is_deeply($results->get_value('name'), [ 'foo' ], 'got my name back');
+ ok($results->is_valid('name'), 'name is valid');
+}
+
+{
+ my $verifier = Data::Verifier->new(
+ profile => {
+ name => {
+ required => 1,
+ type => 'ArrayRef[Str]'
+ }
+ }
+ );
+
my $results = $verifier->verify({ name => [ 'foo', 'bar' ], bar => 'reject me' });
ok($results->success, 'success');
Please sign in to comment.
Something went wrong with that request. Please try again.