sal/osl/w32/procimpl.cxx |   18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

New commits:
commit 8ecd161ac9c36bcabd98c6d5e22c72fbb8d03502
Author:     Roland Baudin <rolan...@free.fr>
AuthorDate: Wed Mar 13 22:47:18 2019 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Mon Mar 18 21:17:09 2019 +0100

    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 <sberg...@redhat.com>
    (cherry picked from commit cf89d6dbfd72e60e459b2ffef313a6d8b477857b)
    Reviewed-on: https://gerrit.libreoffice.org/69392

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();
     }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to