[LON-CAPA-cvs] cvs: loncom /publisher loncfile.pm

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 10 Sep 2004 20:05:03 -0000


albertel		Fri Sep 10 16:05:03 2004 EDT

  Modified files:              
    /loncom/publisher	loncfile.pm 
  Log:
  - BUG#3065, / in gfilename were troublesome
  
  
Index: loncom/publisher/loncfile.pm
diff -u loncom/publisher/loncfile.pm:1.62 loncom/publisher/loncfile.pm:1.63
--- loncom/publisher/loncfile.pm:1.62	Tue Aug 24 17:21:41 2004
+++ loncom/publisher/loncfile.pm	Fri Sep 10 16:05:03 2004
@@ -9,7 +9,7 @@
 #  and displays a page showing the results of the action.
 #
 #
-# $Id: loncfile.pm,v 1.62 2004/08/24 21:21:41 albertel Exp $
+# $Id: loncfile.pm,v 1.63 2004/09/10 20:05:03 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -289,7 +289,7 @@
 }
 
 sub cleanDest {
-    my ($request,$dest,$subdir)=@_;
+    my ($request,$dest,$subdir,$fn)=@_;
     #remove bad characters
     my $foundbad=0;
     if ($subdir && $dest =~/\./) {
@@ -300,6 +300,13 @@
 	$foundbad=1;
 	$dest=~s/[\#\?&%\"]//g;
     }
+    if ($dest=~m|/|) {
+	my ($newpath)=($dest=~m|(.*)/|);
+	if (! -d "$fn/$newpath") {
+	    $request->print("<p><font color=\"red\">".&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.','"<tt>'.$newpath.'</tt>"')."</font></p>");
+	    $dest=~s|.*/||;
+	}
+    }
     if ($foundbad) {
 	$request->print("<p><font color=\"red\">".&mt('Invalid characters in requested name have been removed.')."</font></p>");
     }
@@ -760,7 +767,7 @@
   
     my $doingdir=0;
     if ($ENV{'form.action'} eq 'newdir') { $doingdir=1; }
-    my $newfilename=&cleanDest($r,$ENV{'form.newfilename'},$doingdir);
+    my $newfilename=&cleanDest($r,$ENV{'form.newfilename'},$doingdir,$fn);
     $newfilename=&relativeDest($fn,$newfilename,$uname);
     $r->print('<form action="/adm/cfile" method="post">'.
 	      '<input type="hidden" name="qualifiedfilename" value="'.$fn.'" />'.