Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker
34 changes: 33 additions & 1 deletion lib/View/fileupload/UploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected function validate(string $uploaded_file, stdClass $file, string $error
}

if (is_int($this->options['max_number_of_files']) && (
count($this->get_file_objects()) >= $this->options['max_number_of_files'])
$this->getRealFilesCount() >= $this->options['max_number_of_files'])
) {
$file->error = 'Too many files uploaded. Please remove this file to continue.';

Expand Down Expand Up @@ -205,6 +205,38 @@ protected function validate(string $uploaded_file, stdClass $file, string $error
return true;
}

/**
* Counts the number of real files excluding those with specific patterns in their names.
*
* @return int The number of real files that do not match the predefined exclusion pattern.
*/
private function getRealFilesCount(): int
{
$files = $this->get_file_objects();

if (empty($files)) {
return 0;
}

$count = 0;

// remove sha1
foreach ($files as $file) {

// Exclude files with sha1 in the name.
// Ex. 70a1af62ebce284ccaa4ab0dc8a37afb5b4cd296_da39a3ee5e6b4b0d3255bfef95601890afd80709|en-US
$pattern = '/^[a-f0-9]{40}_[a-f0-9]{40}\|[a-zA-Z]{2,3}(?:-[a-zA-Z]{4})?(?:-(?:[a-zA-Z]{2}|[0-9]{3}))?(?:-[a-zA-Z0-9]+)*$/';

if (preg_match($pattern, $file->name, $matches)) {
continue;
}

$count++;
}

return $count;
}

protected function up_count_name_callback($matches): string
{
$index = isset($matches[1]) ? intval($matches[1]) + 1 : 1;
Expand Down
Loading