Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

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

Report information
The Basics
Id: 60425
Status: resolved
Priority: 0/
Queue: Data-Verifier

People
Owner: Nobody in particular
Requestors: mail [...] dennis-schoen.de
Cc:
AdminCc:

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

Attachments


MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1282057089-11057-67"
Content-Length: 0
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: binary
Content-Length: 122
Download (untitled) / with headers
text/plain 122b
Data::Verifier derefences fields with type "ArrayRef" if they contain only one element. Attached is a fix and a testcase.
Subject: arrayref_with_single_element.patch
MIME-Version: 1.0
Content-Type: application/octet-stream; name="arrayref_with_single_element.patch"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline; filename="arrayref_with_single_element.patch"
Content-Transfer-Encoding: base64
Content-Length: 1886
diff -ur Data-Verifier-0.36/lib/Data/Verifier.pm Data-Verifier-0.36-fixed/lib/Data/Verifier.pm --- Data-Verifier-0.36/lib/Data/Verifier.pm 2010-08-12 15:21:58.000000000 +0200 +++ Data-Verifier-0.36-fixed/lib/Data/Verifier.pm 2010-08-17 16:51:39.000000000 +0200 @@ -194,11 +194,16 @@ sub _filter_value { my ($self, $filters, $values) = @_; + + my $created_ref = 0; + if(ref($filters) ne 'ARRAY') { $filters = [ $filters ]; + $created_ref = 1; } if(!ref($values)) { $values = [ $values ]; + $created_ref = 1; } foreach my $f (@{ $filters }) { @@ -213,8 +218,7 @@ } } - # 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; diff -ur Data-Verifier-0.36/t/array.t Data-Verifier-0.36-fixed/t/array.t --- Data-Verifier-0.36/t/array.t 2010-03-10 21:23:43.000000000 +0100 +++ Data-Verifier-0.36-fixed/t/array.t 2010-08-17 16:49:27.000000000 +0200 @@ -13,6 +13,26 @@ } ); + 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');
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-11058-1282060771-1941.60425-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 31
Fixed in the just-uploaded 0.37


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.