From: Jens Frank Date: Mon, 9 Aug 2004 21:37:27 +0000 (+0000) Subject: Fix for Bug [ 720843 ]: Replace invalid chars in uploaded file names instead of cutti... X-Git-Tag: 1.5.0alpha1~2446 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=commitdiff_plain;h=5df9f462f83185c134883181b74b0595bfcfe29c;p=lhc%2Fweb%2Fwiklou.git Fix for Bug [ 720843 ]: Replace invalid chars in uploaded file names instead of cutting off the end of the string --- diff --git a/includes/SpecialUpload.php b/includes/SpecialUpload.php index f95717e5dd..f9e5365a31 100644 --- a/includes/SpecialUpload.php +++ b/includes/SpecialUpload.php @@ -92,9 +92,11 @@ class UploadForm { if ( "" != $this->mOname ) { $basename = strrchr( $this->mOname, "/" ); + if ( false === $basename ) { $basename = $this->mOname; } else ( $basename = substr( $basename, 1 ) ); + $ext = strrchr( $basename, "." ); if ( false === $ext ) { $ext = ""; } else { $ext = substr( $ext, 1 ); } @@ -106,6 +108,16 @@ class UploadForm { $this->mainUploadForm( WfMsg( "minlength" ) ); return; } + + $changed_name = false; + $bn = preg_replace ( "/[^".Title::legalChars()."]/", '-', $basename ); + if ( 0 != strcmp( $bn, $basename ) ) + { + $changed_name = true; + $basename = $bn; + } + + $nt = Title::newFromText( $basename ); if( !$nt ) { return $this->uploadError( wfMsg( "illegalfilename", htmlspecialchars( $basename ) ) ); @@ -126,7 +138,7 @@ class UploadForm { if ( ! $this->mIgnoreWarning ) { $warning = ''; - if( 0 != strcmp( ucfirst( $basename ), $this->mUploadSaveName ) ) { + if( $changed_name || 0 != strcmp( ucfirst( $basename ), $this->mUploadSaveName ) ) { $warning .= '
  • '.wfMsg( "badfilename", htmlspecialchars( $this->mUploadSaveName ) ).'
  • '; }