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:
parent
865c8565af
commit
3b047b58ce
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user