blib/lib/GetWeb/Util.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 74 CC 4 SCAR 22.2
CC
4
Cov
0%
safeRequest
20.0
getRefTag
2.0
getFormRefTag
2.0
CRAP 9.2
1 package GetWeb::Util;
2  
3 use GetWeb::File;
4 use URI::URL;
5  
6 use strict;
7  
8 sub getRefTag
9 {
10 "*** References from this document ***\n";
11 }
12  
13 sub getFormRefTag
14 {
15 "*** Form section (ignore) ***\n";
16 }
17  
18 sub untaintURL
19 {
20 my $url = shift;
21  
22 $url =~ /\\/ and die "illegal url: $url";
23 $url =~ /^file/ and die "file does not pass taint-check";
24 $url =~ /(.+)/;
25 $1;
26 }
27  
28 sub safeRequest
29 {
30 my $fullString = shift;
31 my $cwd = shift;
32 my $method = shift || 'GET';
33  
34 $fullString =~ s/^\s+//;
35  
36 if ($cwd eq '')
37 {
38 my $config = MailBot::Config::current;
39 $cwd = $config -> getPubDir;
40 }
41  
42 my $url;
43 if ($fullString =~ s%^file:/*%%)
44 {
45 $url = newlocal GetWeb::File($fullString);
46 }
47 else
48 {
49 $fullString = untaintURL($fullString);
50 $url = new URI::URL($fullString);
51 defined $url or
52 die "could not parse url $fullString";
53 }
54  
55 my $scheme = $url -> scheme;
56 if ($scheme eq 'news' or
57 $scheme eq 'mailto')
58 {
59 die "UNAVAILABLE: $scheme is not supported\n";
60 }
61  
62 my $request = new HTTP::Request($method,$url);
63 $scheme eq 'ftp' and
64 $request -> header('Accept','text/html'); # get dir list as HTML
65 $request;
66 }
67  
68 1;