blib/lib/Sanitize.pm

filter: Statementstmt 48.6% 35 / 72 Branchbran 38.1% 16 / 42 Conditioncond 28.5% 6 / 21 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 40.7% 64 / 157 CC 29 SCAR 52.0
CC
29
Cov
42%
_process
228.1
sanitize
6.0
validate
2.1
CRAP 181.7
↑ Summary
1 package Sanitize;
2
3 1 ▶use 5.016003;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 require Exporter;
6 1 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
7
8 1 our @ISA = qw(Exporter);
9 1 our %EXPORT_TAGS = ( 'all' => [ qw() ] );
10 1 our @EXPORT_OK = qw(sanitize validate);
11 1 our @EXPORT = qw(sanitize validate);
12 1 our $VERSION = '1.00';
13
14 sub sanitize
15 0 ▶{
Subroutine sanitize: not called CC=2 SCAR=17.9
Pod documented
16 0 my ($s, @args) = @_;
17 0 ▶ if(!$s) { return ""; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($s) 0 0 0
18 0 my ($state, $result) = _process(@_);
19 0 return $result;
20 }
21
22 sub validate
23 1 ▶{
Subroutine validate: called CC=2 SCAR=7.4
Pod documented
24 1 my ($s) = @_;
25 0 ▶ if(!$s) { return 0; }
Branch: 1 branch
BranchTrueFalseTotal
unless ($s) 0 1 1
26 1 my ($state, $result) = _process(@_);
27 1 return $state;
28 }
29
30 sub _process
31 1 ▶{
Subroutine _process: called CC=27 SCAR=54.3
32 1 my ($s, %opts) = @_;
33
34 1 ▶ if($opts{lc('alpha')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"alpha"}) 0 1 1
35 {
36 0 $s =~ s/[^A-Za-z0-9]//g;
37 }
38 1 ▶ if($opts{lc('hex')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"hex"}) 0 1 1
39 {
40 0 $s =~ s/[^A-Fa-f0-9]//g;
41 }
42 1 ▶ if($opts{lc('number')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"number"}) 0 1 1
43 {
44 0 $s =~ s/[^0-9]//g;
45 }
46 1 ▶ if($opts{lc('html')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"html"}) 0 1 1
47 {
48 0 $s =~ s/</&lt;/g;
49 0 $s =~ s/>/&gt;/g;
50 }
51 1 ▶ if($opts{lc('ltrim')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"ltrim"}) 0 1 1
52 {
53 0 $s =~ s/^\s+//g;
54 }
55 1 ▶ if($opts{lc('rtrim')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"rtrim"}) 0 1 1
56 {
57 0 $s =~ s/\s+$//g;
58 }
59 1 ▶ if($opts{lc('trim')} || $opts{lc('nospace')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"trim"} or $opts{"nospace"}) 0 1 1
Condition33%1/3
$opts{"trim"} or $opts{"nospace"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$opts{"trim"} or $opts{"nospace"}
$opts{"trim"} $opts{"nospace"}
Truth table33%1/3
A or B
A= $opts{"trim"}B= $opts{"nospace"}
ABresult
1X1
011
000
60 {
61 0 $s =~ s/\s+//g;
62 }
63 1 ▶ if($opts{lc('noquotes')} || $opts{lc('noquote')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"noquotes"} or $opts{"noquote"}) 0 1 1
Condition33%1/3
$opts{"noquotes"} or $opts{"noquote"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$opts{"noquotes"} or $opts{"noquote"}
$opts{"noquotes"} $opts{"noquote"}
Truth table33%1/3
A or B
A= $opts{"noquotes"}B= $opts{"noquote"}
ABresult
1X1
011
000
64 {
65 0 $s =~ s/"//g;
66 0 $s =~ s/'//g;
67 }
68 1 ▶ if($opts{lc('noencodings')} || $opts{lc('noencoding')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"noencodings"} or $opts{"noencoding"}) 0 1 1
Condition33%1/3
$opts{"noencodings"} or $opts{"noencoding"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$opts{"noencodings"} or $opts{"noencoding"}
$opts{"noencodings"} $opts{"noencoding"}
Truth table33%1/3
A or B
A= $opts{"noencodings"}B= $opts{"noencoding"}
ABresult
1X1
011
000
69 {
70 0 $s =~ s/%[0-9A-Fa-f]{2}//g;
71 }
72 1 ▶ if($opts{lc('password')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"password"}) 0 1 1
73 {
74 0 $s =~ s/./*/g;
75 }
76 1 ▶ if($opts{lc('email')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"email"}) 0 1 1
77 {
78 0 my ($name, $host) = split('@', $s);
79 0 ▶ if(!$name || !$host) { return (0, ""); }
Branch: 1 branch
BranchTrueFalseTotal
unless ($name and $host) 0 0 0
Condition0%0/3
$name and $host
!ll&&!rl&&r
000
MC/DC0%0/2
$name and $host
$name $host
Truth table0%0/3
A and B
A= $nameB= $host
ABresult
0X0
100
111
80 0 $name = (split(' ', $name))[-1];
81 0 $host = (split(' ', $host))[0];
82 0 $name =~ s/[^A-Za-z0-9\.\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}~]//g;
83 0 $host =~ s/[^A-Za-z0-9\.\-]//g;
84 0 $host =~ s/[\.\-]$//g;
85 0 $s = $name . '@' . $host;
86 }
87 1 ▶ if($opts{lc('ip')} && $opts{lc('port')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"ip"} and $opts{"port"}) 0 1 1
Condition33%1/3
$opts{"ip"} and $opts{"port"}
!ll&&!rl&&r
100
MC/DC0%0/2
$opts{"ip"} and $opts{"port"}
$opts{"ip"} $opts{"port"}
Truth table33%1/3
A and B
A= $opts{"ip"}B= $opts{"port"}
ABresult
0X0
100
111
88 {
89 0 ▶ if($s =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5})/)
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5})/u) { } 0 0 0
90 {
91 0 $s = $1;
92 }
93 0 else { $s = ""; }
94 }
95 1 ▶ if($opts{lc('ip')} && !$opts{lc('port')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"ip"} and not $opts{"port"}) 0 1 1
Condition33%1/3
$opts{"ip"} and not $opts{"port"}
!ll&&!rl&&r
100
MC/DC0%0/2
$opts{"ip"} and not $opts{"port"}
$opts{"ip"} not $opts{"port"}
Truth table33%1/3
A and not(B)
A= $opts{"ip"}B= not $opts{"port"}
ABresult
0X0
100
111
96 {
97 0 ▶ if($s =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/)
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/u) { } 0 0 0
98 {
99 0 $s = $1;
100 }
101 0 else { $s = ""; }
102 }
103 1 ▶ if($opts{lc('port')} && !$opts{lc('ip')})
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"port"} and not $opts{"ip"}) 0 1 1
Condition33%1/3
$opts{"port"} and not $opts{"ip"}
!ll&&!rl&&r
100
MC/DC0%0/2
$opts{"port"} and not $opts{"ip"}
$opts{"port"} not $opts{"ip"}
Truth table33%1/3
A and not(B)
A= $opts{"port"}B= not $opts{"ip"}
ABresult
0X0
100
111
104 {
105 0 ▶ if($s =~ /(\:\d{1,5})/)
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /(\:\d{1,5})/u) { } 0 0 0
106 {
107 0 $s = $1;
108 0 $s =~ s/\://g;
109 }
110 0 else { $s = ""; }
111 }
112 1 ▶ return ($s eq $_[0] ? 1 : 0, $s);
Branch: 1 branch
BranchTrueFalseTotal
$s eq $_[0] ? : 1 0 1
113 }
114
115 1 1;
116 __END__
↑ Summary