Actions
action #111584
openupload_logs issue uploading files with space in the filename
Start date:
2022-05-25
Due date:
% Done:
0%
Estimated time:
Description
Observation¶
Calling upload_logs
with a filename like
/root/result/screenshots/first_visit/login.js/Trento login page -- remain here if wrong password (failed).png
It result in an error like
bash: syntax error near unexpected token `('
http://1c242.qa.suse.de/tests/203#step/test_trento_web/57
Steps to reproduce¶
use Mojo::Base 'publiccloud::basetest';
use base 'consoletest';
use strict;
use testapi;
sub run {
my ($self, $args) = @_;
$self->select_serial_terminal;
assert_script_run 'echo "Hello World!" > echo.log';
assert_script_run 'echo "Hello Space!" > "echo\ space.log"';
upload_logs('echo.log');
upload_logs('echo space.log');
}
Expected result¶
both echo.log
and echo space.log
available in the Log&Asset page
Updated by osukup over 2 years ago
missing shell quoting in testate.pm
probadly best solution -> https://metacpan.org/pod/String::ShellQuote
Updated by tinita over 2 years ago
This looks easy to fix. The current code is:
my $cmd = "curl --form upload=\@$file --form upname=$upname ";
So this needs to be quoted. Ideally with https://metacpan.org/pod/String::ShellQuote to make sure any filename will work.
The subroutine is currently not covered, btw:
https://app.codecov.io/gh/os-autoinst/os-autoinst/blob/master/testapi.pm
Updated by mpagot over 2 years ago
I give it a try to
sub upload_logs {
my $file = shift;
...
(my $escaped_basename = $basename) =~ s/\ /%20/g;
...
my $cmd = 'curl --form upload=@"'.$file.'" ';
$cmd .= '--form upname="'.$upname.'" ';
$cmd .= show_curl_progress_meter();
$cmd .= autoinst_url("/uploadlog/$escaped_basename");
...
return $upname;
}
Result is like
curl --form upload=@"echo space.log" --form upname="hello_world-echo space.log" http://10.0.2.2:20013/9j2u_Ppv4yUkuZzl/uploadlog/echo%20space.log; echo f801X-$?-
error:
curl: (26) Failed to open/read local data from file/application
Actions