[Libreoffice-commits] core.git: sal/osl

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Mar 18 14:20:30 UTC 2019


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

New commits:
commit cf89d6dbfd72e60e459b2ffef313a6d8b477857b
Author:     Roland Baudin <roland65 at free.fr>
AuthorDate: Wed Mar 13 22:47:18 2019 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Mon Mar 18 15:20:07 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 <sbergman at redhat.com>

diff --git a/sal/osl/w32/procimpl.cxx b/sal/osl/w32/procimpl.cxx
index 418ccd40e661..9f0595395dad 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();
     }
 


More information about the Libreoffice-commits mailing list