[Libreoffice-commits] core.git: sw/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 3 07:54:10 UTC 2019


 sw/source/uibase/dochdl/swdtflvr.cxx |   37 ++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

New commits:
commit b81ea32945d553a712d651fe472ece921ac64d10
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Apr 2 16:48:56 2019 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Apr 3 09:53:47 2019 +0200

    tdf#124500: convert short path names from drag-n-drop to long names
    
    ... otherwise link URLs with short names like 2E23~1.PNG would be
    inaccessible from the network, or after copy to a different directory
    or system, where the autogenerated short name might be different.
    
    Change-Id: Ice0b2fa205a25aba232e960cad2615a527cba05a
    Reviewed-on: https://gerrit.libreoffice.org/70145
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index e74e3b7af3ca..ab949d3635be 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -72,6 +72,13 @@
 #include <unotools/streamwrap.hxx>
 #include <vcl/graphicfilter.hxx>
 
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#include <o3tl/char16_t2wchar_t.hxx>
+#include <osl/file.hxx>
+#endif
+
 #include <svx/unomodel.hxx>
 #include <fmturl.hxx>
 #include <fmtinfmt.hxx>
@@ -2469,9 +2476,33 @@ bool SwTransferable::PasteGrf( TransferableDataHelper& rData, SwWrtShell& rSh,
                 OUString sDesc;
                 SwTransferable::CheckForURLOrLNKFile( rData, sText, &sDesc );
 
-                aBkmk = INetBookmark(
-                        URIHelper::SmartRel2Abs(INetURLObject(), sText, Link<OUString *, bool>(), false ),
-                        sDesc );
+                sText = URIHelper::SmartRel2Abs(INetURLObject(), sText, Link<OUString*, bool>(),
+                    false);
+
+#ifdef _WIN32
+                // Now that the path could be modified after SwTransferable::CheckForURLOrLNKFile,
+                // where it could have been converted to URL, and made sure it's actually converted
+                // to URL in URIHelper::SmartRel2Abs, we can finally convert file: URL back to
+                // system path to make sure we don't use short path.
+                // It looks not optimal, when we could apply GetLongPathNameW right to the original
+                // pasted filename. But I don't know if (1) all arriving strings are system paths;
+                // and (2) if SwTransferable::CheckForURLOrLNKFile could result in a different short
+                // path, so taking a safe route.
+                if (sText.startsWithIgnoreAsciiCase("file:"))
+                {
+                    // tdf#124500: Convert short path to long path which should be used in links
+                    OUString sSysPath;
+                    osl::FileBase::getSystemPathFromFileURL(sText, sSysPath);
+                    std::unique_ptr<sal_Unicode[]> aBuf(new sal_Unicode[32767]);
+                    DWORD nCopied = GetLongPathNameW(o3tl::toW(sSysPath.getStr()),
+                                                     o3tl::toW(aBuf.get()), 32767);
+                    if (nCopied && nCopied < 32767)
+                        sText = URIHelper::SmartRel2Abs(INetURLObject(), aBuf.get(),
+                                                        Link<OUString*, bool>(), false);
+                }
+#endif
+
+                aBkmk = INetBookmark(sText, sDesc);
                 bCheckForGrf = true;
                 bCheckForImageMap = SwPasteSdr::Replace == nAction;
             }


More information about the Libreoffice-commits mailing list