[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm
www
lon-capa-cvs@mail.lon-capa.org
Fri, 10 Jan 2003 14:50:08 -0000
www Fri Jan 10 09:50:08 2003 EDT
Modified files:
/loncom/lonnet/perl lonnet.pm
Log:
Had to implement filename filters for uploaded files (photos, etc).
Several users in the workshop had really strange filenames, and LON-CAPA
would choke on those, leaving the user rather puzzled.
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.314 loncom/lonnet/perl/lonnet.pm:1.315
--- loncom/lonnet/perl/lonnet.pm:1.314 Thu Jan 9 17:45:51 2003
+++ loncom/lonnet/perl/lonnet.pm Fri Jan 10 09:50:08 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.314 2003/01/09 22:45:51 www Exp $
+# $Id: lonnet.pm,v 1.315 2003/01/10 14:50:08 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -857,8 +857,15 @@
sub userfileupload {
my ($formname,$coursedoc)=@_;
my $fname=$ENV{'form.'.$formname.'.filename'};
+# Replace Windows backslashes by forward slashes
$fname=~s/\\/\//g;
+# Get rid of everything but the actual filename
$fname=~s/^.*\/([^\/]+)$/$1/;
+# Replace spaces by underscores
+ $fname=~s/\s+/\_/g;
+# Replace all other weird characters by nothing
+ $fname=~s/[^\w\.]//g;
+# See if there is anything left
unless ($fname) { return 'error: no uploaded file'; }
chop($ENV{'form.'.$formname});
# Create the directory if not present