| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 0 | $s =~ s/[^A-Za-z0-9]//g; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | 1 | ▶ | if($opts{lc('hex')}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 0 | $s =~ s/[^A-Fa-f0-9]//g; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 1 | ▶ | if($opts{lc('number')}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | { | ||||||||||||||||||||||||||||
| 44 | 0 | $s =~ s/[^0-9]//g; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | 1 | ▶ | if($opts{lc('html')}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||
| 48 | 0 | $s =~ s/</</g; | |||||||||||||||||||||||||||
| 49 | 0 | $s =~ s/>/>/g; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 1 | ▶ | if($opts{lc('ltrim')}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | { | ||||||||||||||||||||||||||||
| 53 | 0 | $s =~ s/^\s+//g; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 1 | ▶ | if($opts{lc('rtrim')}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||
| 57 | 0 | $s =~ s/\s+$//g; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | 1 | ▶ | if($opts{lc('trim')} || $opts{lc('nospace')}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opts{"trim"} or $opts{"nospace"}
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"}
| |||||||||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||||||||
| 61 | 0 | $s =~ s/\s+//g; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 1 | ▶ | if($opts{lc('noquotes')} || $opts{lc('noquote')}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opts{"noquotes"} or $opts{"noquote"}
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"}
| |||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||
| 65 | 0 | $s =~ s/"//g; | |||||||||||||||||||||||||||
| 66 | 0 | $s =~ s/'//g; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 1 | ▶ | if($opts{lc('noencodings')} || $opts{lc('noencoding')}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opts{"noencodings"} or $opts{"noencoding"}
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"}
| |||||||||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||||||||
| 70 | 0 | $s =~ s/%[0-9A-Fa-f]{2}//g; | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | 1 | ▶ | if($opts{lc('password')}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | { | ||||||||||||||||||||||||||||
| 74 | 0 | $s =~ s/./*/g; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 1 | ▶ | if($opts{lc('email')}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||
| 78 | 0 | my ($name, $host) = split('@', $s); | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | if(!$name || !$host) { return (0, ""); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$name and $host
MC/DC0%0/2
$name and $host
$name
$host
Truth table0%0/3
A and B
A= $nameB= $host
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$opts{"ip"} and $opts{"port"}
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"}
| |||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if($s =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5})/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||
| 91 | 0 | $s = $1; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 0 | else { $s = ""; } | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 1 | ▶ | if($opts{lc('ip')} && !$opts{lc('port')}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opts{"ip"} and not $opts{"port"}
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"}
| |||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if($s =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | { | ||||||||||||||||||||||||||||
| 99 | 0 | $s = $1; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | 0 | else { $s = ""; } | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 1 | ▶ | if($opts{lc('port')} && !$opts{lc('ip')}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$opts{"port"} and not $opts{"ip"}
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"}
| |||||||||||||||||||||||||||||
| 104 | { | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if($s =~ /(\:\d{1,5})/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 1 | 1; | |||||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||||||