public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH http-server] upload: allow whitespaces in filenames
@ 2022-11-04 10:56 Dominik Csapak
  2022-11-04 13:17 ` Thomas Lamprecht
  0 siblings, 1 reply; 2+ messages in thread
From: Dominik Csapak @ 2022-11-04 10:56 UTC (permalink / raw)
  To: pve-devel

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





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [pve-devel] [PATCH http-server] upload: allow whitespaces in filenames
  2022-11-04 10:56 [pve-devel] [PATCH http-server] upload: allow whitespaces in filenames Dominik Csapak
@ 2022-11-04 13:17 ` Thomas Lamprecht
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2022-11-04 13:17 UTC (permalink / raw)
  To: Proxmox VE development discussion, Dominik Csapak

Am 04/11/2022 um 11:56 schrieb Dominik Csapak:
> 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@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


we could also just use the existing PVE::Tools::trim() that does what we
want already?


w.r.t. parse_content_disposition: I'm not really sure if that's the best
fit for the altered "architecture" any more, iow. rather no easy one line
+- change. Maybe it's better to drop it, I found no other usage in our
packages.




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-04 13:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-04 10:56 [pve-devel] [PATCH http-server] upload: allow whitespaces in filenames Dominik Csapak
2022-11-04 13:17 ` Thomas Lamprecht

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal