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.
This commit is contained in:
Tim Kosse 2015-09-14 11:42:38 +02:00
parent 865c8565af
commit 3b047b58ce

View File

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