Kaydet (Commit) cf89d6db authored tarafından Roland Baudin's avatar Roland Baudin Kaydeden (comit) Stephan Bergmann

tdf#96038 Make shell function work with paths containing spaces

Explanation of the patch: in the Windows version of LibreOffice,
when calling the basic Shell(...) function (located in
basic/source/runtime/methods.cxx), a function is_batch_file()
is called in turn, to check if the program file path to execute
is a batch or an executable.

The function is_batch_file() is located in sal/osl/w32/procimpl.cxx
and simply checks if the file extension is equal to bat (or cmd or
btm).

This works as expected, except when the file path contains space
characters. In that case, the file path is *quoted* before the
call to is_batch_file() and for a batch file the file extension
becomes bat" (note the quote) instead of bat, and thus the call
to is_batch_file() wrongly returns false in that case.

In this patch, the issue is fixed by changing the function
get_file_extension() to make it return the correct extension
(i.e. without the '"' character) when the file name is quoted.

Change-Id: Ib6e74da87b23d64db925c17f8a26617f1a86a83d
Reviewed-on: https://gerrit.libreoffice.org/69230
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst dd3d5f7c
......@@ -319,10 +319,20 @@ namespace /* private */
OUString get_file_extension(const OUString& file_name)
{
sal_Int32 index = file_name.lastIndexOf('.');
if ((index != -1) && ((index + 1) < file_name.getLength()))
return file_name.copy(index + 1);
// Quoted file name
if ((file_name.indexOf(L'"') == 0) && (file_name.lastIndexOf(L'"') == (file_name.getLength() - 1)))
{
sal_Int32 index = file_name.lastIndexOf('.');
if ((index != -1) && ((index + 2) < file_name.getLength()))
return file_name.copy(index + 1, file_name.getLength() - (index + 2));
}
// Unquoted file name
else
{
sal_Int32 index = file_name.lastIndexOf('.');
if ((index != -1) && ((index + 1) < file_name.getLength()))
return file_name.copy(index + 1);
}
return OUString();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment