diff --git a/main/document/create_document.php b/main/document/create_document.php index 0033f49106..2e2711b973 100755 --- a/main/document/create_document.php +++ b/main/document/create_document.php @@ -351,8 +351,14 @@ $form->addElement('hidden', 'title_edited', 'false', 'id="title_edited"'); */ function document_exists($filename) { global $dir; - return DocumentManager::documentExists( - $dir.$filename.'.html', + // Clean up the name, only ASCII characters should stay. (and strict) + $cleanName = replace_dangerous_char($filename, 'strict'); + + // No "dangerous" files + $cleanName = disable_dangerous_file($cleanName); + + return !DocumentManager::documentExists( + $dir.$cleanName.'.html', api_get_course_info(), api_get_session_id(), api_get_group_id() diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 4e58a5564e..cd672df89b 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -4615,7 +4615,7 @@ class DocumentManager $dir = null; } - if (!empty($dir)) { + if (!empty($dir) && $dir != '/') { $dir = $dir.'/'; } @@ -4709,14 +4709,14 @@ class DocumentManager $fileNameWithSuffix = Database::escape_string($fileNameWithSuffix); // Check if pathname already exists inside document table - $tbl_document = Database::get_course_table(TABLE_DOCUMENT); - $sql = "SELECT id, path FROM $tbl_document + $table = Database::get_course_table(TABLE_DOCUMENT); + $sql = "SELECT id, path FROM $table WHERE filetype = 'file' AND c_id = $courseId AND ( path = '".$fileNameEscape."' OR - path ='$fileNameWithSuffix' + path = '$fileNameWithSuffix' ) AND (session_id = 0 OR session_id = $sessionId) "; @@ -4772,8 +4772,6 @@ class DocumentManager { $counter = 1; $filePath = $path.$name; - error_log('getUniqueFileName'); - error_log($filePath); $uniqueName = $name; while($documentExists = self::documentExists( $filePath, @@ -4783,10 +4781,9 @@ class DocumentManager )) { $uniqueName = self::addSuffixToFileName($name, '_'.$counter); $filePath = $path.$uniqueName; - error_log($filePath); $counter++; } - error_log($uniqueName); + return $uniqueName; }