Added spaces to hyphens validation in upload files

ofaj
José Loguercio 9 years ago
parent c6a73493c7
commit c76975b479
  1. 5
      main/inc/lib/api.lib.php
  2. 7
      main/inc/lib/document.lib.php
  3. 6
      main/inc/lib/fileUpload.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);
}
/**

@ -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

@ -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);

Loading…
Cancel
Save