summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorRoland Baudin <roland65@free.fr>2019-03-13 22:47:18 +0100
committerStephan Bergmann <sbergman@redhat.com>2019-03-18 21:17:09 +0100
commit8ecd161ac9c36bcabd98c6d5e22c72fbb8d03502 (patch)
treefd8429b94b9e0982d2920c589943ff489d70853e /sal
parent38792118d9e8bbbf1d1ee1f1874b32991fb1442b (diff)
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: Stephan Bergmann <sbergman@redhat.com> (cherry picked from commit cf89d6dbfd72e60e459b2ffef313a6d8b477857b) Reviewed-on: https://gerrit.libreoffice.org/69392
Diffstat (limited to 'sal')
-rw-r--r--sal/osl/w32/procimpl.cxx18
1 files changed, 14 insertions, 4 deletions
diff --git a/sal/osl/w32/procimpl.cxx b/sal/osl/w32/procimpl.cxx
index d9cbaaa19617..49465bb6f163 100644
--- a/sal/osl/w32/procimpl.cxx
+++ b/sal/osl/w32/procimpl.cxx
@@ -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();
}