--- loncom/publisher/loncfile.pm 2004/06/10 18:20:16 1.57 +++ loncom/publisher/loncfile.pm 2004/09/10 20:05:03 1.63 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.57 2004/06/10 18:20:16 albertel Exp $ +# $Id: loncfile.pm,v 1.63 2004/09/10 20:05:03 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -289,11 +289,26 @@ sub checksuffix { } sub cleanDest { - my ($request,$dest)=@_; + my ($request,$dest,$subdir,$fn)=@_; #remove bad characters + my $foundbad=0; + if ($subdir && $dest =~/\./) { + $foundbad=1; + $dest=~s/\.//g; + } if ($dest=~/[\#\?&%\"]/) { + $foundbad=1; + $dest=~s/[\#\?&%\"]//g; + } + if ($dest=~m|/|) { + my ($newpath)=($dest=~m|(.*)/|); + if (! -d "$fn/$newpath") { + $request->print("
".&mt('You request to create file in directory [_1] which doesn\'t exist. The requested directory path has been removed from the requested file name.','"'.$newpath.'"')."
"); + $dest=~s|.*/||; + } + } + if ($foundbad) { $request->print("".&mt('Invalid characters in requested name have been removed.')."
"); - $dest=~s/[\#\?&%]//g; } return $dest; } @@ -750,7 +765,9 @@ performed and reported to the user. sub phaseone { my ($r,$fn,$uname,$udom)=@_; - my $newfilename=&cleanDest($r,$ENV{'form.newfilename'}); + my $doingdir=0; + if ($ENV{'form.action'} eq 'newdir') { $doingdir=1; } + my $newfilename=&cleanDest($r,$ENV{'form.newfilename'},$doingdir,$fn); $newfilename=&relativeDest($fn,$newfilename,$uname); $r->print('