blib/lib/GetWeb/File.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 41 CC 3 SCAR 14.6
CC
3
Cov
0%
newlocal
6.0
local_path
6.0
BEGIN
2.0
CRAP 4.3
1 package GetWeb::File;
2  
3 use URI::URL::file;
4 use MailBot::Config;
5  
6 @ISA = qw( URI::URL::file );
7 use strict;
8  
9 sub newlocal {
10 my($class, $path) = @_;
11  
12 # untaint path
13
14 # jf fix canonical url mismatch
15  
16 ($path =~ /\.\./)
17 and die "cannot go below public dir";
18 $path = "./".$path unless
19 $path =~ /^\.\//;
20  
21 $path =~ m!^([_a-zA-Z0-9/.?%+-]+)$! or die "unsafe filename: $path\n";
22 $path = $1;
23  
24 # Carp::Croak("Only implemented for Unix file systems")
25 # unless $ostype eq "unix";
26 # XXX: Should implement the same thing for other systems
27  
28 my $url = new URI::URL "file:";
29 $url->path($path);
30 $url;
31 }
32  
33 sub local_path
34 {
35 my $path = URI::URL::file::local_path(@_);
36  
37 # require Cwd;
38 # my $cwd = Cwd::fastcwd();
39 my $config = MailBot::Config::current;
40 my $cwd = $config -> getPubDir();
41 # die "cwd is $cwd";
42 $cwd =~ s:/?$:/:; # force trailing slash on dir
43 $path = (defined $path) ? $cwd . $path : $cwd;
44 $path;
45 }