From 0f4c65dd4f3ebbf346e8fbcf9c0431ffa72f1482 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sun, 24 Jan 2021 19:51:33 +0100 Subject: [PATCH] respecting UTI string rules when constructing native format in wxDataFormat::SetId adding part from https://github.com/wxWidgets/wxWidgets/pull/1995/commits/4ae329472c2c668b4793f2ea388ab2e23069484d --- src/osx/carbon/dataobj.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/osx/carbon/dataobj.cpp b/src/osx/carbon/dataobj.cpp index 7be8a9b864..133804edc6 100644 --- a/src/osx/carbon/dataobj.cpp +++ b/src/osx/carbon/dataobj.cpp @@ -228,15 +228,27 @@ void wxDataFormat::SetId( NativeFormat format ) void wxDataFormat::SetId( const wxString& zId ) { m_type = wxDF_PRIVATE; - m_id = zId; - // in newer macOS version this must conform to a UTI // https://developer.apple.com/library/archive/documentation/General/Conceptual/DevPedia-CocoaCore/UniformTypeIdentifier.html - if ( zId.Find('.') != wxNOT_FOUND ) - m_format = wxCFStringRef(zId); + // first filter characters + wxString utiString = zId; + wxString::iterator it; + for (it = utiString.begin(); it != utiString.end(); ++it) + { + wxUniChar c = *it; + if ( !( c >= 'A' && c <='Z') && !( c >= 'a' && c <='z') && !( c >= '0' && c <='9') && + c != '.' && c !='-' ) + *it= '-'; + } + + m_id = utiString; + + // make sure it follows a reverse DNS notation + if ( utiString.Find('.') != wxNOT_FOUND ) + m_format = wxCFStringRef(utiString); else - m_format = wxCFStringRef(privateUTIPrefix+zId); + m_format = wxCFStringRef(privateUTIPrefix+utiString); } bool wxDataFormat::operator==(const wxDataFormat& format) const