Browse Source

Added spaces to hyphens validation in upload files

José Loguercio 8 years ago
parent
commit
c76975b479
3 changed files with 12 additions and 6 deletions
  1. 3 2
      main/inc/lib/api.lib.php
  2. 5 2
      main/inc/lib/document.lib.php
  3. 4 2
      main/inc/lib/fileUpload.lib.php

+ 3 - 2
main/inc/lib/api.lib.php

@@ -5611,12 +5611,13 @@ function api_is_element_in_the_session($tool, $element_id, $session_id = null) {
  * Replaces "forbidden" characters in a filename string.
  *
  * @param string $filename
+ * @param bool $treat_spaces_as_hyphens
  *
  * @return string
  */
-function api_replace_dangerous_char($filename)
+function api_replace_dangerous_char($filename, $treat_spaces_as_hyphens = true)
 {
-    return URLify::filter($filename, 250, '', true, true, false, false);
+    return URLify::filter($filename, 250, '', true, true, false, false, $treat_spaces_as_hyphens);
 }
 
 /**

+ 5 - 2
main/inc/lib/document.lib.php

@@ -2802,6 +2802,7 @@ class DocumentManager
      * @param bool $index_document index document (search xapian module)
      * @param bool $show_output print html messages
      * @param string $fileKey
+     * @param bool $treat_spaces_as_hyphens
      *
      * @return array|bool
      */
@@ -2814,7 +2815,8 @@ class DocumentManager
         $if_exists = null,
         $index_document = false,
         $show_output = false,
-        $fileKey = 'file'
+        $fileKey = 'file',
+        $treat_spaces_as_hyphens = true
     ) {
         $course_info = api_get_course_info();
         $sessionId = api_get_session_id();
@@ -2845,7 +2847,8 @@ class DocumentManager
                     $show_output,
                     false,
                     null,
-                    $sessionId
+                    $sessionId,
+                    $treat_spaces_as_hyphens
                 );
 
                 // Showing message when sending zip files

+ 4 - 2
main/inc/lib/fileUpload.lib.php

@@ -173,6 +173,7 @@ function process_uploaded_file($uploaded_file, $show_output = true)
  * @param bool $onlyUploadFile
  * @param string $comment
  * @param int $sessionId
+ * @param bool $treat_spaces_as_hyphens
  *
  * So far only use for unzip_uploaded_document function.
  * If no output wanted on success, set to false.
@@ -192,7 +193,8 @@ function handle_uploaded_document(
     $output = true,
     $onlyUploadFile = false,
     $comment = null,
-    $sessionId = null
+    $sessionId = null,
+    $treat_spaces_as_hyphens = true
 ) {
     if (!$userId) {
         return false;
@@ -246,7 +248,7 @@ function handle_uploaded_document(
         return false;
     } else {
         // Clean up the name, only ASCII characters should stay. (and strict)
-        $cleanName = api_replace_dangerous_char($uploadedFile['name']);
+        $cleanName = api_replace_dangerous_char($uploadedFile['name'], $treat_spaces_as_hyphens);
 
         // No "dangerous" files
         $cleanName = disable_dangerous_file($cleanName);