r2161 - in
packages/libdata-formvalidator-perl/branches/upstream/current:
. lib/Data lib/Data/FormValidator t
Gunnar Wolf
gwolf at costa.debian.org
Tue Feb 21 20:18:46 UTC 2006
Author: gwolf
Date: 2006-02-21 20:18:45 +0000 (Tue, 21 Feb 2006)
New Revision: 2161
Added:
packages/libdata-formvalidator-perl/branches/upstream/current/t/credit_card.t
Modified:
packages/libdata-formvalidator-perl/branches/upstream/current/Changes
packages/libdata-formvalidator-perl/branches/upstream/current/MANIFEST
packages/libdata-formvalidator-perl/branches/upstream/current/META.yml
packages/libdata-formvalidator-perl/branches/upstream/current/README
packages/libdata-formvalidator-perl/branches/upstream/current/lib/Data/FormValidator.pm
packages/libdata-formvalidator-perl/branches/upstream/current/lib/Data/FormValidator/Constraints.pm
packages/libdata-formvalidator-perl/branches/upstream/current/lib/Data/FormValidator/Results.pm
packages/libdata-formvalidator-perl/branches/upstream/current/t/11_procedural_match.t
packages/libdata-formvalidator-perl/branches/upstream/current/t/procedural_valid.t
Log:
Load /tmp/tmp.5fV0M9/libdata-formvalidator-perl-4.14 into
packages/libdata-formvalidator-perl/branches/upstream/current.
Modified: packages/libdata-formvalidator-perl/branches/upstream/current/Changes
===================================================================
--- packages/libdata-formvalidator-perl/branches/upstream/current/Changes 2006-02-21 15:37:10 UTC (rev 2160)
+++ packages/libdata-formvalidator-perl/branches/upstream/current/Changes 2006-02-21 20:18:45 UTC (rev 2161)
@@ -1,4 +1,10 @@
+4.14 Fri Feb 17 08:59:40 EST 2006
+ [ENHANCEMENTS]
+ - Consider a field with only a null character to be invalid (Jamie Krasnoo)
+ [BUG FIXES]
+ - Fix bug in cc_number constraint, which was only present when used as a "constraint_method". (Evan A. Zacks)
+
4.13
[BUG FIXES]
- Updated overloading syntax to work with Template::Stash (frank)
Modified: packages/libdata-formvalidator-perl/branches/upstream/current/MANIFEST
===================================================================
--- packages/libdata-formvalidator-perl/branches/upstream/current/MANIFEST 2006-02-21 15:37:10 UTC (rev 2160)
+++ packages/libdata-formvalidator-perl/branches/upstream/current/MANIFEST 2006-02-21 20:18:45 UTC (rev 2161)
@@ -45,6 +45,7 @@
t/constraints_factory.t
t/constraints_invalid_once_only.t
t/constraints_reuse.t
+t/credit_card.t
t/dates.t
t/dates_closure.t
t/dependency_groups.t
Modified: packages/libdata-formvalidator-perl/branches/upstream/current/META.yml
===================================================================
--- packages/libdata-formvalidator-perl/branches/upstream/current/META.yml 2006-02-21 15:37:10 UTC (rev 2160)
+++ packages/libdata-formvalidator-perl/branches/upstream/current/META.yml 2006-02-21 20:18:45 UTC (rev 2161)
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: Data-FormValidator
-version: 4.13
+version: 4.14
author:
- Mark Stosberg <mark at summersault.com>
abstract: |-
@@ -18,16 +18,16 @@
provides:
Data::FormValidator:
file: lib/Data/FormValidator.pm
- version: 4.13
+ version: 4.14
Data::FormValidator::Constraints:
file: lib/Data/FormValidator/Constraints.pm
- version: 4.02
+ version: 4.14
Data::FormValidator::Constraints::Dates:
file: lib/Data/FormValidator/Constraints/Dates.pm
version: 1.01
Data::FormValidator::Constraints::RegexpCommon:
file: lib/Data/FormValidator/Results.pm
- version: 4.13
+ version: 4.14
Data::FormValidator::Constraints::Upload:
file: lib/Data/FormValidator/Constraints/Upload.pm
version: 1.1
@@ -39,5 +39,5 @@
version: 4
Data::FormValidator::Results:
file: lib/Data/FormValidator/Results.pm
- version: 4.13
+ version: 4.14
generated_by: Module::Build version 0.2611
Modified: packages/libdata-formvalidator-perl/branches/upstream/current/README
===================================================================
--- packages/libdata-formvalidator-perl/branches/upstream/current/README 2006-02-21 15:37:10 UTC (rev 2160)
+++ packages/libdata-formvalidator-perl/branches/upstream/current/README 2006-02-21 20:18:45 UTC (rev 2161)
@@ -31,8 +31,8 @@
my $results = Data::FormValidator->check(\%input_hash, \%dfv_profile);
"check" is the recommended method to use to validate forms. It returns
- it's results as a Data::FormValidator::Results object. A deprecated
- method "validate" is also available, returning it's results as an array
+ its results as a Data::FormValidator::Results object. A deprecated
+ method "validate" is also available, returning its results as an array
described below.
use Data::FormValidator;
@@ -314,7 +314,7 @@
match a regular expression.
constraint_methods
- use Data::FormValidator::Constraints (qw:closures);
+ use Data::FormValidator::Constraints qw(:closures);
constraint_methods => {
cc_no => cc_number({fields => ['cc_type']}),
Modified: packages/libdata-formvalidator-perl/branches/upstream/current/lib/Data/FormValidator/Constraints.pm
===================================================================
--- packages/libdata-formvalidator-perl/branches/upstream/current/lib/Data/FormValidator/Constraints.pm 2006-02-21 15:37:10 UTC (rev 2160)
+++ packages/libdata-formvalidator-perl/branches/upstream/current/lib/Data/FormValidator/Constraints.pm 2006-02-21 20:18:45 UTC (rev 2161)
@@ -23,7 +23,7 @@
use strict;
use vars qw/$AUTOLOAD @ISA @EXPORT_OK %EXPORT_TAGS $VERSION/;
-$VERSION = 4.02;
+$VERSION = 4.14;
require Exporter;
@ISA = qw(Exporter);
@@ -428,16 +428,24 @@
# This one is taken from the contributed program to
# MiniVend by Bruce Albrecht
+# XXX raise exception on bad/missing params?
sub cc_number {
- my $dfv = shift;
- my $attrs = pop;
- my $data = $dfv->get_input_data;
+ my $attrs = shift;
+ return undef unless $attrs && ref($attrs) eq 'HASH'
+ && exists $attrs->{fields} && ref($attrs->{fields}) eq 'ARRAY';
- my ($cc_type_field) = @{ $attrs->{fields} };
- return match_cc_number(
- $dfv->get_current_constraint_value,
- $data->{$cc_type_field}
- );
+ my ($cc_type_field) = @{ $attrs->{fields} };
+ return undef unless $cc_type_field;
+
+ return sub {
+ my $dfv = shift;
+ my $data = $dfv->get_input_data;
+
+ return match_cc_number(
+ $dfv->get_current_constraint_value,
+ $data->{$cc_type_field}
+ );
+ };
}
sub match_cc_number {
@@ -638,7 +646,7 @@
Constraints>.
The most flexible way to create constraints to use closures-- a normal seeming
-outer subroutine which returins a customized DFV method subroutine as a result.
+outer subroutine which returns a customized DFV method subroutine as a result.
It's easy to do. These "constraint methods" can be named whatever you like, and
imported normally into the name space where the profile is located.
@@ -777,7 +785,7 @@
my $value = $self->get_current_constraint_name;
-This is useful for building a constraint on the fly based on it's name.
+This is useful for building a constraint on the fly based on its name.
It's used internally as part of the interface to the L<Regexp::Commmon>
regular expressions.
Modified: packages/libdata-formvalidator-perl/branches/upstream/current/lib/Data/FormValidator/Results.pm
===================================================================
--- packages/libdata-formvalidator-perl/branches/upstream/current/lib/Data/FormValidator/Results.pm 2006-02-21 15:37:10 UTC (rev 2160)
+++ packages/libdata-formvalidator-perl/branches/upstream/current/lib/Data/FormValidator/Results.pm 2006-02-21 20:18:45 UTC (rev 2161)
@@ -24,7 +24,7 @@
'bool' => \&_bool_overload_based_on_success,
fallback => 1;
-$VERSION = 4.13;
+$VERSION = 4.14;
=pod
@@ -200,7 +200,7 @@
if (ref $valid{$field}) {
if ( ref $valid{$field} eq 'ARRAY' ) {
for (my $i = 0; $i < scalar @{ $valid{$field} }; $i++) {
- $valid{$field}->[$i] = undef unless (defined $valid{$field}->[$i] and length $valid{$field}->[$i]);
+ $valid{$field}->[$i] = undef unless (defined $valid{$field}->[$i] and length $valid{$field}->[$i] and $valid{$field}->[$i] !~ /^\x00$/);
}
# If all fields are empty, we delete it.
delete $valid{$field} unless grep { defined $_ } @{$valid{$field}};
@@ -208,7 +208,7 @@
}
}
else {
- delete $valid{$field} unless (defined $valid{$field} and length $valid{$field});
+ delete $valid{$field} unless (defined $valid{$field} and length $valid{$field} and $valid{$field} !~ /^\x00$/);
}
}
Modified: packages/libdata-formvalidator-perl/branches/upstream/current/lib/Data/FormValidator.pm
===================================================================
--- packages/libdata-formvalidator-perl/branches/upstream/current/lib/Data/FormValidator.pm 2006-02-21 15:37:10 UTC (rev 2160)
+++ packages/libdata-formvalidator-perl/branches/upstream/current/lib/Data/FormValidator.pm 2006-02-21 20:18:45 UTC (rev 2161)
@@ -31,7 +31,7 @@
use vars qw( $VERSION $AUTOLOAD @ISA @EXPORT_OK %EXPORT_TAGS );
-$VERSION = '4.13';
+$VERSION = '4.14';
require Exporter;
@ISA = qw(Exporter);
@@ -167,9 +167,9 @@
my $results = Data::FormValidator->check(\%input_hash, \%dfv_profile);
-C<check> is the recommended method to use to validate forms. It returns it's results as a
+C<check> is the recommended method to use to validate forms. It returns its results as a
L<Data::FormValidator::Results|Data::FormValidator::Results> object. A
-deprecated method C<validate> is also available, returning it's results as an
+deprecated method C<validate> is also available, returning its results as an
array described below.
use Data::FormValidator;
@@ -524,7 +524,7 @@
=head2 constraint_methods
- use Data::FormValidator::Constraints (qw:closures);
+ use Data::FormValidator::Constraints qw(:closures);
constraint_methods => {
cc_no => cc_number({fields => ['cc_type']}),
Modified: packages/libdata-formvalidator-perl/branches/upstream/current/t/11_procedural_match.t
===================================================================
--- packages/libdata-formvalidator-perl/branches/upstream/current/t/11_procedural_match.t 2006-02-21 15:37:10 UTC (rev 2160)
+++ packages/libdata-formvalidator-perl/branches/upstream/current/t/11_procedural_match.t 2006-02-21 20:18:45 UTC (rev 2161)
@@ -3,7 +3,7 @@
$^W = 1;
-use Test::More tests => 25;
+use Test::More tests => 26;
use Data::FormValidator qw(:validators :matchers);
@@ -47,10 +47,13 @@
$i++;
}
-#Test cc_number seperately since i do not know a valid cc number
+#Test cc_number separately since it takes multiple parameters
my $rv;
+my $num = '4111111111111111';
+eval "\$rv = match_cc_number('$num', 'v')";
+ok(not $@ and ($rv eq $num)) or
+ diag sprintf("%-25s using %-16s", "match_cc_number", "valid value. ");
+
eval "\$rv = match_cc_number('$invalid', 'm')";
-
ok(not $@ and not $rv) or
diag sprintf("%-25s using %-16s", "match_cc_number", "invalid value. ");
-
Added: packages/libdata-formvalidator-perl/branches/upstream/current/t/credit_card.t
===================================================================
--- packages/libdata-formvalidator-perl/branches/upstream/current/t/credit_card.t 2006-02-21 15:37:10 UTC (rev 2160)
+++ packages/libdata-formvalidator-perl/branches/upstream/current/t/credit_card.t 2006-02-21 20:18:45 UTC (rev 2161)
@@ -0,0 +1,98 @@
+use strict;
+# check credit card number validation (the cc_number constraint).
+# note: this constraint is checked directly in 11_procedural_match.t and
+# procedural_valid.t, but here we will test it indirectly through a profile
+
+$^W = 1;
+
+use Data::FormValidator;
+use Data::FormValidator::Constraints qw(:closures);
+use Test::More tests => 25;
+
+my $dfv_profile_old = {
+ required => [qw(credit_card_type credit_card_number)],
+ constraints => {
+ credit_card_number => {
+ constraint => 'cc_number',
+ params => [ qw(credit_card_number credit_card_type) ],
+ },
+ },
+};
+
+# numbers from
+# http://www.verisign.com/support/payflow/manager/selfHelp/testCardNum.html
+# maps type => [ [ invalids ... ], [ valids ... ] ]
+my %cc_numbers = (
+ Visa => [ [ '4000111122223333', ],
+ [ '4111111111111111', '4012888888881881', ] ],
+
+ Mastercard => [ [ '5424111122223333', ],
+ [ '5105105105105100', '5555555555554444', ] ],
+
+ Discover => [ [ '6000111122223333', ],
+ [ '6011111111111117', '6011000990139424', ] ],
+
+ Amex => [ [ '371500001111222', ],
+ [ '378282246310005', '371449635398431', ] ],
+);
+
+while ( my ($card_type, $numbers) = each %cc_numbers ) {
+ foreach my $is_valid ( 0..1 ) {
+ foreach my $n ( @{ $numbers->[$is_valid] } ) {
+ my $msg = ($is_valid ? "Valid" : "Invalid") . ": $card_type/$n";
+ my $input = {
+ credit_card_type => $card_type,
+ credit_card_number => $n,
+ };
+
+ is( validate_q( $input, $dfv_profile_old ), $is_valid, "$msg (old)" );
+ }
+ }
+}
+
+my $dfv_profile_new = eval {
+ {
+ required => [qw(credit_card_type credit_card_number)],
+ constraint_methods => {
+ credit_card_number => cc_number({fields => ['credit_card_type']}),
+ },
+ }
+};
+
+ok( ! $@, "cc_number subroutine runs without error" );
+
+# broken cc_number subroutine in older dfv
+SKIP: {
+ skip "(Older DFV has broken cc_number subroutine)", 12 if $@;
+
+ while ( my ($card_type, $numbers) = each %cc_numbers ) {
+ foreach my $is_valid ( 0..1 ) {
+ foreach my $n ( @{ $numbers->[$is_valid] } ) {
+ my $msg = ($is_valid ? "Valid" : "Invalid") . ": $card_type/$n";
+ my $input = {
+ credit_card_type => $card_type,
+ credit_card_number => $n,
+ };
+
+ is( validate_q( $input, $dfv_profile_new ), $is_valid, "$msg (new)" );
+ }
+ }
+ }
+}
+
+##
+
+sub validate_q {
+ my ( $data, $profile ) = @_;
+
+ my $dfv_result = eval {
+ Data::FormValidator->check($data, $profile);
+ };
+
+ if( $@ ) {
+ diag "Failed check [$@]";
+ return;
+ }
+
+ return ($dfv_result->has_invalid || $dfv_result->has_missing) ? 0 : 1;
+}
Modified: packages/libdata-formvalidator-perl/branches/upstream/current/t/procedural_valid.t
===================================================================
--- packages/libdata-formvalidator-perl/branches/upstream/current/t/procedural_valid.t 2006-02-21 15:37:10 UTC (rev 2160)
+++ packages/libdata-formvalidator-perl/branches/upstream/current/t/procedural_valid.t 2006-02-21 20:18:45 UTC (rev 2161)
@@ -49,16 +49,22 @@
$i++;
}
-#Test cc_number seperately since i do not know a valid cc number
+#Test cc_number separately since it takes multiple parameters
{
my $rv;
+ my $num = '4111111111111111';
+
+ eval "\$rv = match_cc_number('$num', 'v')";
+ ok(not $@ and ($rv eq $num)) or
+ diag sprintf("%-25s using %-16s", "match_cc_number", "valid value. ");
+
eval "\$rv = valid_cc_number('$invalid', 'm')";
-
ok(not $@ and not $rv) or
diag sprintf("%-25s using %-16s", "valid_cc_number", "(invalid value)");
}
$i++;
+$i++;
#Test fake validation routine
{
More information about the Pkg-perl-cvs-commits
mailing list