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

Report information
The Basics
Id:
79491
Status:
rejected
Priority:
Low/Low

People
Owner:
Nobody in particular
Requestors:
vega.james [...] gmail.com
Cc:
AdminCc:

BugTracker
Severity:
Normal
Broken in:
1.00
Fixed in:
(no value)



Subject: type => UNDEF, regex => qr/.../ performs a regex check on the value
Currently, if a parameter has UNDEF as one of the acceptable types, then an undef value will still be checked by a regex validation (after being coerced to an empty string). This means that the regex validation must handle this scenario. It seems to me that the UNDEF type should take precedence here and avoid the regex check. I stumbled upon this recently because I had to use { type => SCALAR|UNDEF, regex => qr/^(foo|bar|)$/ } instead of what I really wanted to express, { type => SCALAR|UNDEF, regex => qr/^(foo|bar)$/ }.
On Thu Sep 06 15:51:09 2012, http://jamessan.myopenid.com/ wrote:
Show quoted text
> Currently, if a parameter has UNDEF as one of the acceptable types,
then
Show quoted text
> an undef value will still be checked by a regex validation (after
being
Show quoted text
> coerced to an empty string). This means that the regex validation
must
Show quoted text
> handle this scenario. > > It seems to me that the UNDEF type should take precedence here and
avoid
Show quoted text
> the regex check. > > I stumbled upon this recently because I had to use { type =>
SCALAR|UNDEF,
Show quoted text
> regex => qr/^(foo|bar|)$/ } instead of what I really wanted to
express, {
Show quoted text
> type => SCALAR|UNDEF, regex => qr/^(foo|bar)$/ }.
Type specs are cumulative, so if you have both a type and a regex they both must pass. I suppose I could special-case this but it all seems a little confusing. In this case I think it'd be saner to simply not allow undef values and make the parameter optional.
From: James McCoy
On Sun Sep 16 13:13:07 2012, DROLSKY wrote:
Show quoted text
> On Thu Sep 06 15:51:09 2012, http://jamessan.myopenid.com/ wrote:
> > Currently, if a parameter has UNDEF as one of the acceptable types,
> then
> > an undef value will still be checked by a regex validation (after
> being
> > coerced to an empty string). This means that the regex validation
> must
> > handle this scenario. > > > > It seems to me that the UNDEF type should take precedence here and
> avoid
> > the regex check. > > > > I stumbled upon this recently because I had to use { type =>
> SCALAR|UNDEF,
> > regex => qr/^(foo|bar|)$/ } instead of what I really wanted to
> express, {
> > type => SCALAR|UNDEF, regex => qr/^(foo|bar)$/ }.
> > Type specs are cumulative, so if you have both a type and a regex they > both must pass. I suppose I could special-case this but it all seems a > little confusing. In this case I think it'd be saner to simply not
allow
Show quoted text
> undef values and make the parameter optional.
Making the parameter optional doesn't work, though. Since the user specified a value (undef), it has to pass the defined validation. I understand it's confusing, though, so feel free to close the report.


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

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