Subject: | REGEX_MATCH fails on input "0" |
The WWW::FieldValidator::REGEX_MATCH fails when the input is "0" - see the attached test case. This is because the test at line 138 only tests against truth rather than definedness. The trivial patch is:
--- lib/WWW/FieldValidator.pm.orig 2019-06-13 22:29:23.770954118 +0100
+++ lib/WWW/FieldValidator.pm 2019-06-13 22:30:18.458767185 +0100
@@ -135,7 +135,7 @@
# Checks to see if input matches the specified pattern.
sub _validateRegex {
my $self = shift;
- my $input = shift || '';
+ my $input = shift // '';
return ($input =~ /$self->{regex}/);
}
although that's 5.10 syntax, of course.
Subject: | wfv.t |
use strict;
use warnings;
use Test::More tests => 11;
use WWW::FieldValidator;
my $validator = WWW::FieldValidator->new (
WWW::FieldValidator::REGEX_MATCH,
'Value must be 0 to 5',
'^[0-5]$'
);
ok !$validator->validate ('donkey'), 'Not donkey';
ok !$validator->validate (''), 'Not empty string';
ok !$validator->validate ('55'), 'Not double digit';
ok !$validator->validate ('-5'), 'Not negative int';
for my $data (0..5) {
ok $validator->validate ($data), "$data is fine";
}
ok !$validator->validate ('6'), 'Not 6';