Skip to content

Commit 45a10b2

Browse files
committedMar 6, 2023
[afs] Percent encode text values when creating/updating fields on
ArcGIS feature services Fixes loss of edits when special characters are used Fixes #51509
1 parent 34a30a1 commit 45a10b2

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed
 

‎src/core/providers/arcgis/qgsarcgisrestutils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,9 @@ QVariant QgsArcGisRestUtils::variantToAttributeValue( const QVariant &variant, Q
15761576

15771577
switch ( expectedType )
15781578
{
1579+
case QVariant::String:
1580+
return QString( QUrl::toPercentEncoding( variant.toString() ) );
1581+
15791582
case QVariant::DateTime:
15801583
case QVariant::Date:
15811584
{

‎tests/src/python/test_qgsarcgisrestutils.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def test_feature_to_json(self):
306306
'a_date_field': 1646352000000,
307307
'a_double_field': 5.5,
308308
'a_int_field': 5,
309-
'a_string_field': 'my string value',
309+
'a_string_field': 'my%20string%20value',
310310
'a_null_value': None},
311311
'geometry': {'x': 1.0, 'y': 2.0}})
312312
# without geometry
@@ -316,7 +316,7 @@ def test_feature_to_json(self):
316316
'a_date_field': 1646352000000,
317317
'a_double_field': 5.5,
318318
'a_int_field': 5,
319-
'a_string_field': 'my string value',
319+
'a_string_field': 'my%20string%20value',
320320
'a_null_value': None}})
321321
# without attributes
322322
context.setObjectIdFieldName('a_int_field')
@@ -325,6 +325,19 @@ def test_feature_to_json(self):
325325
'a_int_field': 5},
326326
'geometry': {'x': 1.0, 'y': 2.0}})
327327

328+
# with special characters
329+
330+
attributes[0] = 'aaa" , . - ; : ä ö ü è é à ? + &'
331+
test_feature.setAttributes(attributes)
332+
res = QgsArcGisRestUtils.featureToJson(test_feature, context, flags=QgsArcGisRestUtils.FeatureToJsonFlags(QgsArcGisRestUtils.FeatureToJsonFlag.IncludeNonObjectIdAttributes))
333+
self.assertEqual(res, {'attributes': {'a_boolean_field': True,
334+
'a_datetime_field': 1646395994000,
335+
'a_date_field': 1646352000000,
336+
'a_double_field': 5.5,
337+
'a_int_field': 5,
338+
'a_string_field': 'aaa%22%20%2C%20.%20-%20%3B%20%3A%20%C3%A4%20%C3%B6%20%C3%BC%20%C3%A8%20%C3%A9%20%C3%A0%20%3F%20%2B%20%26',
339+
'a_null_value': None}})
340+
328341
def test_field_to_json(self):
329342
field = QgsField('my name', QVariant.LongLong)
330343
field.setAlias('my alias')

0 commit comments

Comments
 (0)
Please sign in to comment.