Branch Coverage

blib/lib/CGI/Info.pm
Criterion Covered Total %
branch 358 474 75.5


line true false branch
81 3 151 ref $_[0] eq 'HASH' ? :
83 1 153 if ($args{'expect'} and ref $args{'expect'} ne "ARRAY")
88 1 152 if (not defined $class) { }
4 148 elsif (ref $class) { }
127 9 6 unless ($self->{'script_name'})
139 11 4 if ($ENV{'SCRIPT_NAME'}) { }
148 1 14 if ($ENV{'SCRIPT_FILENAME'}) { }
5 9 elsif ($ENV{'SCRIPT_NAME'} and $ENV{'DOCUMENT_ROOT'}) { }
5 4 elsif ($ENV{'SCRIPT_NAME'} and not $ENV{'DOCUMENT_ROOT'}) { }
0 4 elsif ('File::Spec'->file_name_is_absolute($0)) { }
152 3 2 if ($script_name =~ m[^/(.+)])
158 1 4 if ('File::Spec'->file_name_is_absolute($ENV{'SCRIPT_NAME'}) and -r $ENV{'SCRIPT_NAME'}) { }
167 2 2 if ($script_name =~ m[^/(.+)])
208 5 17 unless ($self->{'script_path'})
230 1 10 unless ($self->{'script_path'})
235 0 11 if ($^O eq 'MSWin32') { }
236 0 0 if ($self->{'script_path'} =~ /(.+)\\.+?$/)
240 11 0 if ($self->{'script_path'} =~ m[(.+)/.+?$])
271 2 6 unless ($self->{'site'})
281 4 3 if ($self->{'logger'})
284 2 0 if ($self->{'site'} and $self->{'cgi_site'})
291 1 4 if ($ENV{'HTTP_HOST'}) { }
3 1 elsif ($ENV{'SERVER_NAME'}) { }
295 1 0 if ($self->{'cgi_site'} =~ /(.*)\.+$/)
300 1 2 if (defined $self->protocol and $self->protocol ne "http")
308 1 0 if ($self->{'logger'})
315 5 0 unless ($self->{'site'})
318 4 1 if ($self->{'site'} =~ m[^https?://(.+)])
321 1 4 unless ($self->{'cgi_site'} =~ m[^https?://])
324 0 1 unless ($protocol)
329 0 5 unless ($self->{'site'} and $self->{'cgi_site'})
332 3 2 if ($self->{'logger'})
347 3 2 if ($self->{'domain'})
352 2 0 if ($self->{'site'})
354 1 1 if ($self->{'domain'} =~ /^www\.(.+)/)
371 3 4 unless ($self->{'cgi_site'})
481 4 158 ref $_[0] eq 'HASH' ? :
483 93 1 if (defined $self->{'paramref'} and !defined($args{'allow'}) || defined $self->{'allow'} && $args{'allow'} eq $self->{'allow'})
487 4 65 if (defined $args{'allow'})
490 3 66 if (defined $args{'expect'})
491 2 1 if (ref $args{'expect'} eq 'ARRAY') { }
497 1 68 if (defined $args{'upload_dir'})
500 1 68 if (defined $args{'logger'})
503 2 67 if ($self->{'logger'})
511 6 63 if (not $ENV{'GATEWAY_INTERFACE'} && $ENV{'REQUEST_METHOD'}) { }
44 19 elsif ($ENV{'REQUEST_METHOD'} eq 'GET' or $ENV{'REQUEST_METHOD'} eq 'HEAD') { }
16 3 elsif ($ENV{'REQUEST_METHOD'} eq 'POST') { }
0 3 elsif ($ENV{'REQUEST_METHOD'} eq 'OPTIONS') { }
1 2 elsif ($ENV{'REQUEST_METHOD'} eq 'DELETE') { }
512 5 1 if (@ARGV) { }
0 1 elsif ($stdin_data) { }
1 0 elsif (not $self->{'args_read'}) { }
514 5 0 if (defined $pairs[0])
515 1 4 if ($pairs[0] eq '--robot') { }
1 3 elsif ($pairs[0] eq '--mobile') { }
1 2 elsif ($pairs[0] eq '--search-engine') { }
1 1 elsif ($pairs[0] eq '--tablet') { }
544 1 1 if $line eq "quit"
550 41 3 if (my $query = $ENV{'QUERY_STRING'}) { }
551 1 40 if (defined $content_type and $content_type =~ m[multipart/form-data]i)
560 2 14 unless (defined $ENV{'CONTENT_LENGTH'})
565 0 14 if ($self->{'max_upload_size'} >= 0 and $content_length > $self->{'max_upload_size'})
573 3 11 if (not defined $content_type or $content_type =~ m[application/x-www-form-urlencoded]) { }
8 3 elsif ($content_type =~ m[multipart/form-data]i) { }
1 2 elsif ($content_type =~ m[text/xml]i) { }
1 1 elsif ($content_type =~ m[application/json]i) { }
575 1 2 if ($stdin_data) { }
578 1 1 if (read(STDIN, $buffer, $content_length) != $content_length)
590 1 7 unless (defined $self->{'upload_dir'})
596 1 6 unless ("File::Spec"->file_name_is_absolute($self->{'upload_dir'}))
603 2 4 unless (-d $self->{'upload_dir'})
610 0 4 unless (-w $self->{'upload_dir'})
618 4 0 if ($content_type =~ /boundary=(\S+)$/)
626 0 1 if ($stdin_data) { }
629 0 1 if (read(STDIN, $buffer, $content_length) != $content_length)
644 0 1 if ($stdin_data) { }
650 0 1 if (read(STDIN, $buffer, $content_length) != $content_length)
665 0 1 if ($stdin_data) { }
668 0 1 if (read(STDIN, $buffer, $content_length) != $content_length)
695 1 52 unless (scalar @pairs)
707 4 98 unless $key
711 98 0 if (defined $value) { }
720 25 73 if ($self->{'allow'})
722 11 14 unless (exists $self->{'allow'}{$key})
723 0 11 if ($self->{'logger'})
730 9 5 if (defined $self->{'allow'}{$key})
731 7 2 unless ($value =~ /$self->{'allow'}{$key}/)
732 0 7 if ($self->{'logger'})
740 2 78 if ($self->{'expect'} and &List::MoreUtils::none(sub { $_ eq $key; } , @{$$self{"expect"};}))
745 67 11 if (not defined $ENV{'REQUEST_METHOD'} or $ENV{'REQUEST_METHOD'} eq "GET")
747 0 64 if ($value =~ /(\%27)|(\')|(\-\-)|(\%23)|(\#)/xi or $value =~ /((\%3D)|(=))[^\n]*((\%27)|(\')|(\-\-)|(\%3B)|(;))/i or $value =~ /\w*((\%27)|(\'))((\%6F)|o|(\%4F))((\%72)|r|(\%52))/xi or $value =~ /((\%27)|(\'))union/xi or $value =~ /select[[a-z]\s\*]from/xi or $value =~ /\sAND\s1=1/xi or $value =~ /exec(\s|\+)+(s|x)p\w+/xi)
754 0 3 if ($self->{'logger'})
755 0 0 if ($ENV{'REMOTE_ADDR'}) { }
764 0 64 if ($value =~ m[((\%3C)|<)((\%2F)|/)*[a-z0-9\%]+((\%3E)|>)]xi or $value =~ /((\%3C)|<)[^\n]+((\%3E)|>)/i)
766 0 0 if ($self->{'logger'})
772 0 64 if ($value eq "../")
773 0 0 if ($self->{'logger'})
780 71 4 if (length $value > 0)
782 5 66 if ($FORM{$key} and $FORM{$key} ne $value) { }
790 9 40 unless (%FORM)
794 2 38 if ($self->{'logger'})
834 1 25 unless (defined $field)
838 4 21 if ($self->{'allow'} and not exists $self->{'allow'}{$field})
845 20 1 if (defined $self->params)
856 11 8 if (ref $_[0] eq 'HASH') { }
0 8 elsif (scalar(@_) % 2 == 0) { }
866 0 19 unless $warning
867 0 19 if ($self eq "CGI::Info")
874 0 19 if ($self->{'syslog'})
878 0 0 if (ref($self->{'syslog'} eq "HASH"))
886 0 19 if ($self->{'logger'}) { }
19 0 elsif (not defined $self->{'syslog'}) { }
913 0 4 if ($self->{'logger'})
918 0 4 if ($self->{'logger'})
921 0 4 if ($total_bytes == 0)
925 4 0 unless ($stdin_data)
931 0 4 unless ($stdin_data)
946 2 32 if ($line =~ /^--\Q$boundary\E--$/)
949 8 24 if ($line =~ /^--\Q$boundary\E$/) { }
16 8 elsif ($in_header) { }
950 0 8 if ($writing_file) { }
4 4 elsif (defined $key) { }
959 6 10 if (length $line == 0) { }
8 2 elsif ($line =~ /^Content-Disposition: (.+)/i) { }
963 8 0 if ($field =~ /name="(.+?)"/)
966 4 4 if ($field =~ /filename="(.+)?"/)
968 2 2 do { $filename =~ m[[\\/\|]] } ? :
4 0 defined $filename ? :
981 0 2 unless (open $fout, ">", $full_path)
991 4 4 if ($writing_file) { }
999 2 0 if ($writing_file)
1016 35 0 if ($args->{'filename'} =~ m<(^[\w\+_\040\#\(\)\{\}\[\]/\-\^,\.:;&%\@\\~]+\$?$)>)
1033 11 27 if (defined $self->{'is_mobile'})
1038 3 24 if (my $ch_ua_mobile = $ENV{'HTTP_SEC_CH_UA_MOBILE'})
1039 1 2 if ($ch_ua_mobile eq "?1")
1044 1 25 if ($ENV{'HTTP_X_WAP_PROFILE'})
1051 16 9 if (my $agent = $ENV{'HTTP_USER_AGENT'})
1052 2 14 if ($agent =~ /.+(Android|iPhone).+/)
1058 1 13 if ($agent =~ m[(android|bb\d+|meego).+mobile|avantgo|bada/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino]i or substr($ENV{'HTTP_USER_AGENT'}, 0, 4) =~ m[1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-]i)
1065 0 9 if (defined $remote and $self->{'cache'})
1066 0 0 if (my $type = $self->{'cache'}->get("$remote/$agent"))
1071 7 6 unless ($self->{'browser_detect'})
1072 7 0 if (eval { do { require HTTP::BrowserDetect } })
1077 13 0 if ($self->{'browser_detect'})
1080 0 2 if ($is_mobile and $self->{'cache'} and defined $remote)
1099 1 5 if (defined $self->{'is_tablet'})
1103 1 4 if ($ENV{'HTTP_USER_AGENT'} and $ENV{'HTTP_USER_AGENT'} =~ /.+(iPad|TabletPC).+/) { }
1123 7 28 unless ($self->params)
1135 12 28 if (defined $rc) { }
1141 1 27 if ($rc and $self->{'logger'})
1145 28 0 defined $rc ? :
1158 2 19 if ($ENV{'SCRIPT_URI'} and $ENV{'SCRIPT_URI'} =~ m[^(.+)://.+])
1161 2 17 if ($ENV{'SERVER_PROTOCOL'} and $ENV{'SERVER_PROTOCOL'} =~ m[^HTTP/])
1166 14 3 if (defined $port)
1167 14 0 if (defined(my $name = getservbyport($port, 'tcp'))) { }
0 0 elsif ($port == 80) { }
0 0 elsif ($port == 443) { }
1168 12 2 if ($name =~ /https?/) { }
0 2 elsif ($name eq 'www') { }
1183 0 5 if ($ENV{'REMOTE_ADDR'})
1218 1 14 ref $_[0] eq 'HASH' ? :
1221 0 15 if ($^O eq "MSWin32")
1227 3 12 unless (ref $self)
1231 4 11 if ($ENV{'C_DOCUMENT_ROOT'} and -d $ENV{'C_DOCUMENT_ROOT'})
1233 2 2 if (-d $dir and -w $dir)
1237 2 0 if (-d $dir and -w $dir)
1241 1 10 if ($ENV{'DOCUMENT_ROOT'} and -d $ENV{'DOCUMENT_ROOT'})
1243 1 0 if (-d $dir and -w $dir)
1247 3 7 $params{'default'} ? :
1265 0 9 if ($ENV{'C_DOCUMENT_ROOT'} and -d $ENV{'C_DOCUMENT_ROOT'}) { }
3 10 elsif ($ENV{'DOCUMENT_ROOT'} and -d $ENV{'DOCUMENT_ROOT'}) { }
1272 6 0 unless ("File::Spec"->file_name_is_absolute($script_name))
1275 0 6 if ($script_name =~ /.cgi\-bin.*/)
1278 6 0 if (-f $script_name)
1279 0 6 if ($^O eq 'MSWin32') { }
1280 0 0 if ($script_name =~ /(.+)\\.+?$/)
1284 6 0 if ($script_name =~ m[(.+)/.+?$])
1302 1 3 unless (ref $self)
1306 1 3 if (defined $dir)
1312 3 2 if (defined $rc and length $rc and -d $rc and -w $rc)
1317 0 3 if not defined $dir or length $dir == 0
1339 3 16 if (defined $self->{'is_robot'})
1346 7 9 unless ($remote and $agent)
1351 3 6 if ($agent =~ /.+bot|bytespider|msnptc|is_archiver|backstreet|spider|scoutjet|gingersoftware|heritrix|dodnetdotcom|yandex|nutch|ezooms|plukkie|nova\.6scan\.com|Twitterbot|adscanner|python-requests|Mediatoolkitbot|NetcraftSurveyAgent|Expanse|serpstatbot|DreamHost SiteMonitor 1.0/i)
1358 2 4 if (my $referrer = $ENV{'HTTP_REFERER'})
1400 2 0 if ($referrer =~ /\)/ or &List::MoreUtils::any(sub { $_ =~ /^$referrer/; } , @crawler_lists))
1401 2 0 if ($self->{'logger'})
1404 0 2 if ($self->{'cache'})
1412 0 4 if ($self->{'cache'})
1413 0 0 if (defined $remote and $self->{'cache'})
1414 0 0 if (my $type = $self->{'cache'}->get("$remote/$agent"))
1420 3 1 unless ($self->{'browser_detect'})
1421 3 0 if (eval { do { require HTTP::BrowserDetect } })
1426 4 0 if ($self->{'browser_detect'})
1428 1 1 if (defined $is_robot and $self->{'logger'})
1431 2 2 defined $is_robot && $is_robot ? :
1432 2 2 if ($self->{'logger'})
1436 2 2 if ($is_robot)
1437 0 2 if ($self->{'cache'})
1445 0 2 if ($self->{'cache'})
1469 6 19 if (defined $self->{'is_search_engine'})
1476 8 11 unless ($remote and $agent)
1483 0 11 if ($self->{'cache'})
1485 0 0 if (defined $remote and $self->{'cache'})
1486 0 0 if (my $type = $self->{'cache'}->get("$remote/$agent"))
1494 0 11 if ($agent =~ /www\.majestic12\.co\.uk|facebookexternal/)
1495 0 0 if ($self->{'cache'})
1501 7 4 unless ($self->{'browser_detect'})
1502 7 0 if (eval { do { require HTTP::BrowserDetect } })
1507 11 0 if (my $browser = $self->{'browser_detect'})
1509 1 10 if (not $is_search and $agent =~ m[SeznamBot/])
1512 0 6 if ($is_search and $self->{'cache'})
1521 0 0 if (defined $hostname and $hostname =~ /google|msnbot|bingbot|amazonbot/ and not $hostname =~ /^google-proxy/)
1522 0 0 if ($self->{'cache'})
1560 8 13 if ($self->is_mobile)
1563 6 7 if ($self->is_search_engine)
1566 3 4 if ($self->is_robot)
1593 3 10 if (ref $_[0] eq 'HASH') { }
9 1 elsif (scalar(@_) % 2 == 0) { }
1601 3 10 unless (defined $params{'cookie_name'})
1606 4 6 unless ($self->{'jar'})
1607 1 3 unless (defined $ENV{'HTTP_COOKIE'})
1618 6 3 if (exists $self->{'jar'}{$params{'cookie_name'}})
1640 0 2 unless (defined $field)
1645 0 2 unless ($self->{'jar'})
1646 0 0 unless (defined $ENV{'HTTP_COOKIE'})
1657 2 0 if (exists $self->{'jar'}{$field})
1672 4 8 if (my $status = shift()) { }
5 3 elsif (not defined $self->{'status'}) { }
1675 4 1 if (defined(my $method = $ENV{'REQUEST_METHOD'}))
1676 1 3 if ($method eq 'OPTIONS' or $method eq 'DELETE') { }
1 4 elsif ($method eq 'POST' and not defined $ENV{'CONTENT_LENGTH'}) { }
1699 1 2 if (ref $_[0] eq 'HASH') { }
1 1 elsif (scalar(@_) % 2 == 0) { }
1722 1 10 unless ($class eq "CGI::Info")
1736 153 4 if $param eq "DESTROY"
1740 0 4 if ref $self ne "CGI::Info"