Skip to content
Permalink
Browse files

Correctly escape more json strings

  • Loading branch information
nyalldawson committed May 5, 2016
1 parent 729c703 commit 819ed86a6967ccb42f69cade41997ef92f0ebde9
Showing with 13 additions and 2 deletions.
  1. +7 −1 src/core/qgsjsonutils.cpp
  2. +6 −1 tests/src/python/test_qgsjsonutils.py
@@ -113,9 +113,15 @@ QString QgsJSONUtils::encodeValue( const QVariant &value )

default:
case QVariant::String:
QString v = value.toString().replace( '"', "\\\"" )
QString v = value.toString()
.replace( '\\', "\\\\" )
.replace( '"', "\\\"" )
.replace( '\r', "\\r" )
.replace( '\b', "\\b" )
.replace( '\t', "\\t" )
.replace( '/', "\\/" )
.replace( '\n', "\\n" );

return v.prepend( '"' ).append( '"' );
}
}
@@ -92,7 +92,12 @@ def testEncodeValue(self):
self.assertEqual(QgsJSONUtils.encodeValue('string'), '"string"')
self.assertEqual(QgsJSONUtils.encodeValue('str\ning'), '"str\\ning"')
self.assertEqual(QgsJSONUtils.encodeValue('str\ring'), '"str\\ring"')
self.assertEqual(QgsJSONUtils.encodeValue('str"ing'), '"str\\"ing"')
self.assertEqual(QgsJSONUtils.encodeValue('str\bing'), '"str\\bing"')
self.assertEqual(QgsJSONUtils.encodeValue('str\ting'), '"str\\ting"')
self.assertEqual(QgsJSONUtils.encodeValue('str\\ing'), '"str\\\\ing"')
self.assertEqual(QgsJSONUtils.encodeValue('str\\ning'), '"str\\\\ning"')
self.assertEqual(QgsJSONUtils.encodeValue('str\n\\\\ing'), '"str\\n\\\\\\\\ing"')
self.assertEqual(QgsJSONUtils.encodeValue('str/ing'), '"str\\/ing"')

def testFeatureToGeoJSON(self):
""" test converting features to GeoJSON """

0 comments on commit 819ed86

Please sign in to comment.
You can’t perform that action at this time.