Skip Menu |

This queue is for tickets about the Validate-Tiny CPAN distribution.

Report information
The Basics
Id: 104235
Status: resolved
Estimated: 3 hours (180 min)
Worked: 3 hours (180 min)
Priority: 0/
Queue: Validate-Tiny

People
Owner: MINIMAL [...] cpan.org
Requestors: valkoles [...] gmail.com
Cc:
AdminCc:

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



Subject: few bugs
Date: Tue, 5 May 2015 11:32:41 -0400
To: bug-Validate-Tiny [...] rt.cpan.org
From: val <valkoles [...] gmail.com>
Provided checks aren't exactly correct. For example if I want to check that { var => '' } was passed for validation is_required will return error message though variable and its value were provided (empty string is a valid value. As undef value). IMHO is_required check should look something like: sub is_required { my $err_msg = shift || 'Required'; return sub { exists $_[ 1 ] -> { $_[ 2 ] } ? undef : $err_msg } } and current check might be renamed to something like is_defined_and_non_empty. Though just introducing is_defined instead sounds as a good idea to me. Standard check is_a has line: return undef if !defined($_[0]) || $_[0] eq ''; which is incorrect in case $_[ 0 ] is an object of a class that overrides string comparison operators (cmp/eq/..). In such case validation dies in the middle of process. I'd recommend at least replacing it with: return undef unless defined $_[ 0 ] && length $_[ 0 ]; # or even ref $_[ 0 ] instead this line. Thanks for fixing filters for undefined value.
Thanks! Fixed in version 1.551. Instead of changing is_required, I added a new constraint called is_existing. On Tue May 05 11:32:49 2015, valkoles@gmail.com wrote: Show quoted text
> Provided checks aren't exactly correct. > > For example if I want to check that { var => '' } was passed for > validation is_required will return error message though variable and > its value were provided (empty string is a valid value. As undef > value). IMHO is_required check should look something like: > > sub is_required { > my $err_msg = shift || 'Required'; > return sub { exists $_[ 1 ] -> { $_[ 2 ] } ? undef : $err_msg } > } > > and current check might be renamed to something like > is_defined_and_non_empty. > Though just introducing is_defined instead sounds as a good idea to > me. > > > Standard check is_a has line: > return undef if !defined($_[0]) || $_[0] eq ''; > > which is incorrect in case $_[ 0 ] is an object of a class that > overrides string comparison operators (cmp/eq/..). In such case > validation dies in the middle of process. > I'd recommend at least replacing it with: > return undef > unless defined $_[ 0 ] > && length $_[ 0 ]; # or even ref $_[ 0 ] instead this line. > > > Thanks for fixing filters for undefined value.