| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CGI::ValidOp::Check; |
|
2
|
20
|
|
|
20
|
|
66089
|
use strict; |
|
|
20
|
|
|
|
|
41
|
|
|
|
20
|
|
|
|
|
665
|
|
|
3
|
20
|
|
|
20
|
|
108
|
use warnings; |
|
|
20
|
|
|
|
|
35
|
|
|
|
20
|
|
|
|
|
1864
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
20
|
|
|
20
|
|
118
|
use base qw/ CGI::ValidOp::Base /; |
|
|
20
|
|
|
|
|
38
|
|
|
|
20
|
|
|
|
|
2616
|
|
|
6
|
20
|
|
|
20
|
|
120
|
use Carp; |
|
|
20
|
|
|
|
|
40
|
|
|
|
20
|
|
|
|
|
15977
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my @ALLOWED_TYPES = ( qw/ regexp code /); # types of reference we allow for checks |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
11
|
|
|
|
|
|
|
sub PROPERTIES { |
|
12
|
|
|
|
|
|
|
{ |
|
13
|
1060
|
|
|
1060
|
0
|
5660
|
validator => undef, |
|
14
|
|
|
|
|
|
|
errmsg => undef, |
|
15
|
|
|
|
|
|
|
name => undef, |
|
16
|
|
|
|
|
|
|
params => undef, |
|
17
|
|
|
|
|
|
|
allow_tainted => 0, |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
22
|
|
|
|
|
|
|
# params are optional parameters passed in, e.g. "check_name(3,4)" |
|
23
|
|
|
|
|
|
|
sub init { |
|
24
|
1063
|
|
|
1063
|
0
|
1696
|
my $self = shift; |
|
25
|
1063
|
|
|
|
|
2505
|
my( $check_name, @params ) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
1063
|
|
100
|
|
|
3564
|
$check_name ||= 'default'; |
|
28
|
1063
|
|
|
|
|
1868
|
my $pkg = ref $self; |
|
29
|
1063
|
100
|
|
|
|
5213
|
croak qq/No such check ("$check_name") in package "$pkg"./ |
|
30
|
|
|
|
|
|
|
unless $self->can( $check_name ); |
|
31
|
1062
|
|
|
|
|
3693
|
my( $validator, $errmsg ) = $self->$check_name; |
|
32
|
1062
|
|
|
|
|
2290
|
my $validator_type = ref $validator; |
|
33
|
1062
|
100
|
100
|
|
|
13858
|
croak join ' ', "Disallowed reference type for validator. You used $validator_type; valid types are:", @ALLOWED_TYPES |
|
34
|
|
|
|
|
|
|
unless $validator_type and grep /^$validator_type$/i, @ALLOWED_TYPES; |
|
35
|
|
|
|
|
|
|
|
|
36
|
1060
|
|
|
|
|
9835
|
$self->SUPER::init({ |
|
37
|
|
|
|
|
|
|
validator => $validator, |
|
38
|
|
|
|
|
|
|
errmsg => $errmsg, |
|
39
|
|
|
|
|
|
|
name => $check_name, |
|
40
|
|
|
|
|
|
|
params => \@params, |
|
41
|
|
|
|
|
|
|
}); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
45
|
|
|
|
|
|
|
# called by a check to indicate success: "pass( $value )" |
|
46
|
|
|
|
|
|
|
sub pass { |
|
47
|
322
|
|
|
322
|
0
|
2127
|
my $self = shift; |
|
48
|
322
|
|
|
|
|
810
|
my( $value ) = @_; |
|
49
|
322
|
|
|
|
|
1530
|
( $value, undef ); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
53
|
|
|
|
|
|
|
# called by a check to indicate failure "fail( $errmsg )" |
|
54
|
|
|
|
|
|
|
sub fail { |
|
55
|
115
|
|
|
115
|
0
|
261
|
my $self = shift; |
|
56
|
115
|
|
|
|
|
216
|
my( $errmsg ) = @_; |
|
57
|
115
|
|
|
|
|
462
|
( undef, $errmsg ); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
61
|
|
|
|
|
|
|
# check to see what type of validator we have and call the appropriate sub |
|
62
|
|
|
|
|
|
|
sub check { |
|
63
|
1075
|
|
|
1075
|
1
|
2399
|
my $self = shift; |
|
64
|
1075
|
|
|
|
|
2314
|
my( $tainted ) = @_; |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# trim whitespace |
|
67
|
1075
|
100
|
|
|
|
3384
|
if (defined $tainted) { |
|
68
|
1008
|
|
|
|
|
2907
|
$tainted =~ s/^\s+//; |
|
69
|
1008
|
|
|
|
|
2710
|
$tainted =~ s/\s+$//; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
1075
|
|
|
|
|
2948
|
my $check_sub = 'check_'. lc ref $self->validator; |
|
73
|
1075
|
|
|
|
|
2970
|
$self->$check_sub( $tainted, $self->validator ); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
77
|
|
|
|
|
|
|
# this method makes the decision about whether the test passed or failed |
|
78
|
|
|
|
|
|
|
# if it gets undef it returns it with no error message |
|
79
|
|
|
|
|
|
|
# if the regex then returns undef it returns an error |
|
80
|
|
|
|
|
|
|
sub check_regexp { |
|
81
|
644
|
|
|
644
|
1
|
895
|
my $self = shift; |
|
82
|
644
|
|
|
|
|
1220
|
my( $tainted, $validator ) = @_; |
|
83
|
644
|
100
|
|
|
|
1436
|
return( undef, undef ) unless defined $tainted; |
|
84
|
606
|
|
|
|
|
9076
|
$tainted =~ /($validator)/; |
|
85
|
606
|
100
|
|
|
|
1473
|
return $1 unless wantarray; |
|
86
|
600
|
100
|
|
|
|
3989
|
defined $1 |
|
87
|
|
|
|
|
|
|
? ( $1, undef ) |
|
88
|
|
|
|
|
|
|
: ( undef, $self->errmsg ); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
92
|
|
|
|
|
|
|
# this method expects the coderef to call either pass or fail |
|
93
|
|
|
|
|
|
|
sub check_code { |
|
94
|
443
|
|
|
443
|
1
|
846
|
my $self = shift; |
|
95
|
443
|
|
|
|
|
964
|
my( $tainted, $validator ) = @_; |
|
96
|
443
|
|
|
|
|
1427
|
my( $value, $errmsg ) = &$validator( $tainted, $self->params ); |
|
97
|
440
|
100
|
100
|
|
|
3320
|
croak 'Validator returned a tainted value' |
|
98
|
|
|
|
|
|
|
if $self->is_tainted( $value ) |
|
99
|
|
|
|
|
|
|
and ! $self->allow_tainted; |
|
100
|
|
|
|
|
|
|
wantarray |
|
101
|
439
|
100
|
|
|
|
3476
|
? ( $value, $errmsg ) |
|
102
|
|
|
|
|
|
|
: $value; |
|
103
|
|
|
|
|
|
|
} |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|
106
|
|
|
|
|
|
|
sub default { |
|
107
|
|
|
|
|
|
|
( |
|
108
|
|
|
|
|
|
|
sub { |
|
109
|
2
|
|
|
2
|
|
403
|
croak 'You must override CGI::ValidOp::Check::check() with your own code.'; |
|
110
|
|
|
|
|
|
|
}, |
|
111
|
3
|
|
|
3
|
0
|
638
|
'Parameter $label contained invalid data.', |
|
112
|
|
|
|
|
|
|
) |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
1; |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
__END__ |