Skip to content

Commit 731ac4f

Browse files
committed
Re-write MimeData Uri concat and split function to deal with layer names and urls that contain the ':' character
1 parent 2db4f35 commit 731ac4f

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

src/core/qgsmimedatautils.cpp

+39-7
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* (at your option) any later version. *
1313
* *
1414
***************************************************************************/
15+
#include <QStringList>
16+
1517
#include "qgsmimedatautils.h"
1618

1719
#include "qgsdataitem.h"
@@ -39,20 +41,50 @@ QgsMimeDataUtils::Uri::Uri( QgsLayerItem* layerItem )
3941

4042
QgsMimeDataUtils::Uri::Uri( QString& encData )
4143
{
42-
QRegExp rx( "^([^:]+):([^:]+):([^:]+):(.+)" );
43-
if ( rx.indexIn( encData ) != -1 )
44+
QStringList parts;
45+
QChar split = ':';
46+
QChar escape = '\\';
47+
QString part;
48+
bool inEscape = false;
49+
for (int i = 0; i < encData.length(); ++i)
50+
{
51+
if (encData.at(i) == escape && !inEscape)
52+
{
53+
inEscape = true;
54+
}
55+
else if (encData.at(i) == split && !inEscape)
56+
{
57+
parts << part;
58+
part = "";
59+
}
60+
else
61+
{
62+
part += encData.at(i);
63+
inEscape = false;
64+
}
65+
}
66+
if (!part.isEmpty())
67+
{
68+
parts << part;
69+
}
70+
71+
if ( parts.size() == 4 )
4472
{
45-
layerType = rx.cap( 1 );
46-
providerKey = rx.cap( 2 );
47-
name = rx.cap( 3 );
48-
uri = rx.cap( 4 );
73+
layerType = parts[0];
74+
providerKey = parts[1];
75+
name = parts[2];
76+
uri = parts[3];
4977
QgsDebugMsg( "type: " + layerType + " key: " + providerKey + " name: " + name + " uri: " + uri );
5078
}
5179
}
5280

5381
QString QgsMimeDataUtils::Uri::data() const
5482
{
55-
return layerType + ":" + providerKey + ":" + name + ":" + uri;
83+
QString escapedName = name;
84+
QString escapeUri = uri;
85+
escapedName.replace(":", "\\:");
86+
escapeUri.replace(":", "\\:");
87+
return layerType + ":" + providerKey + ":" + escapedName + ":" + escapeUri;
5688
}
5789

5890
// -----

0 commit comments

Comments
 (0)