From 7a37ebbeb3afc8ba375c1aa2549bc42bc419ef06 Mon Sep 17 00:00:00 2001 From: Joachim Kueter Date: Mon, 16 Feb 2026 20:03:22 +0100 Subject: [PATCH] FIX: Clean filenames with double spaces (#37256) * Clean filenames with double spaces If a filename contains double spaces, it can get uploaded in Dolibarr exactly as it is. When listing the file or trying to download it, the dolibarr functions clear double spaces in the filename. In particular the alpha parameter for GETPOST. This results in files being uploaded (e.g. attachments for invoices) than can get listed but remain inaccessible and even cannot get deleted via UI. We either need to fix all these places to accept double spaces or we change a single location, when we sanitize filenames. * removed white space --- htdocs/core/lib/functions.lib.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d4d4ec2332d..5ac76b1c506 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1783,6 +1783,7 @@ function dol_sanitizeFileName($str, $newstr = '_', $unaccent = 1, $includequotes $tmp = preg_replace('/\s+\-([^\s])/', ' _$1', $tmp); $tmp = preg_replace('/\s+\-$/', '', $tmp); $tmp = str_replace('..', '', $tmp); + $tmp = preg_replace('/\s{2,}/', ' ', $tmp); return $tmp; } @@ -1815,6 +1816,8 @@ function dol_sanitizePathName($str, $newstr = '_', $unaccent = 1) $tmp = preg_replace('/\s+\-([^\s])/', ' _$1', $tmp); $tmp = preg_replace('/\s+\-$/', '', $tmp); $tmp = str_replace('..', '', $tmp); + $tmp = preg_replace('/\s{2,}/', ' ', $tmp); + return $tmp; }