[pve-devel] [PATCH http-server] upload: allow whitespaces in filenames

Dominik Csapak d.csapak at proxmox.com
Fri Nov 4 11:56:44 CET 2022


some fields (e.g. filename) can contain spaces, but our 'trim' function,
would only return the value until the first whitespace character instead
of removing leading/trailing white space. this lead to giving the wrong
filename to the api call (e.g. 'foo' instead of 'foo (1).iso') which
would reject it because of the 'wrong' extension

this patch fixes that by using a more robust regex replacement

fixes commit:
0fbcbc2 ("fix #3990: multipart upload: rework to fix uploading small files")

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
while looking at the code, i noticed there is now the unused function
'parse_content_disposition', so i'd suggest we either use that instead,
or remove it if we don't need it

 src/PVE/APIServer/AnyEvent.pm | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/PVE/APIServer/AnyEvent.pm b/src/PVE/APIServer/AnyEvent.pm
index 4296ded..81adf50 100644
--- a/src/PVE/APIServer/AnyEvent.pm
+++ b/src/PVE/APIServer/AnyEvent.pm
@@ -1187,8 +1187,9 @@ sub file_upload_multipart {
     my ($self, $reqstate, $auth, $method, $path, $rstate) = @_;
 
     my $trim = sub {
-	$_[0] =~ /\s*(\S+)/;
-	return $1;
+	my $value = shift;
+	$value =~ s/^\s+|\s+$//g;
+	return $value;
     };
 
     eval {
-- 
2.30.2






More information about the pve-devel mailing list