Blob Blame History Raw
commit 8f29de5231e348d356b5f3962225362e8fd87ba9
Author: Tim Kosse <tim.kosse@filezilla-project.org>
Date:   Mon Sep 14 11:42:38 2015 +0200

    Escape filenames in wxFileDataObject::GetDataSize/GetDataHere
    
    On wxGTK, wxFileDataObject::SetData calls g_filename_from_uri which
    percent-decodes URIs. No corresponding percent-encoding was done in
    wxFileDataObject::GetDataSize/GetDataHere. Use g_filename_to_uri instead in so
    that filenames are properly escaped.
    
    This commit also fixes the data being truncated if it contains non-ASCII
    characters on wide-character builds, see the memcpy arguments in the original
    code.

diff --git a/src/gtk/dataobj.cpp b/src/gtk/dataobj.cpp
index 9a39607..2d1f43c 100644
--- a/src/gtk/dataobj.cpp
+++ b/src/gtk/dataobj.cpp
@@ -235,16 +235,21 @@ wxTextDataObject::GetAllFormats(wxDataFormat *formats,
 
 bool wxFileDataObject::GetDataHere(void *buf) const
 {
-    wxString filenames;
+    char* out = reinterpret_cast<char*>(buf);
 
     for (size_t i = 0; i < m_filenames.GetCount(); i++)
     {
-        filenames += wxT("file:");
-        filenames += m_filenames[i];
-        filenames += wxT("\r\n");
+        char* uri = g_filename_to_uri(m_filenames[i].mbc_str(), 0, 0);
+        if (uri)
+        {
+            size_t const len = strlen(uri);
+            strcpy(out, uri);
+            out += len;
+            *(out++) = '\r';
+            *(out++) = '\n';
+        }
     }
-
-    memcpy( buf, filenames.mbc_str(), filenames.length() + 1 );
+    *out = 0;
 
     return true;
 }
@@ -255,9 +260,11 @@ size_t wxFileDataObject::GetDataSize() const
 
     for (size_t i = 0; i < m_filenames.GetCount(); i++)
     {
-        // This is junk in UTF-8
-        res += m_filenames[i].length();
-        res += 5 + 2; // "file:" (5) + "\r\n" (2)
+        char* uri = g_filename_to_uri(m_filenames[i].mbc_str(), 0, 0);
+        if (uri) {
+            res += strlen(uri) + 2; // Including "\r\n"
+            g_free(uri);
+        }
     }
 
     return res + 1;