Skip to content

Commit 9d17f25

Browse files
committed
Convert WMS GetFeatureInfo GML to UTF-8 supported by Expat, fixes #9082
1 parent a4c365c commit 9d17f25

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/core/qgsgml.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,17 @@ class CORE_EXPORT QgsGml : public QObject
5050
~QgsGml();
5151

5252
/** Does the Http GET request to the wfs server
53+
* Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.
5354
* @param uri GML URL
5455
* @param wkbType wkbType to retrieve
5556
* @param extent retrieved extents
5657
* @return 0 in case of success
5758
*/
5859
int getFeatures( const QString& uri, QGis::WkbType* wkbType, QgsRectangle* extent = 0 );
5960

60-
/** Read from GML data. Constructor uri param is ignored */
61+
/** Read from GML data. Constructor uri param is ignored
62+
* Supports only UTF-8, UTF-16, ISO-8859-1, ISO-8859-1 XML encodings.
63+
*/
6164
int getFeatures( const QByteArray &data, QGis::WkbType* wkbType, QgsRectangle* extent = 0 );
6265

6366
/** Get parsed features for given type name */

src/core/qgsgmlschema.h

+1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class CORE_EXPORT QgsGmlSchema: public QObject
8585

8686
/** Guess GML schema from data if XSD does not exist.
8787
* Currently only recognizes UMN Mapserver GetFeatureInfo GML response.
88+
* Supports only UTF-8, UTF-16, ISO-8859-1, US-ASCII XML encodings.
8889
* @param data GML data
8990
* @return true in case of success */
9091
bool guessSchema( const QByteArray &data );

src/providers/wms/qgswmsprovider.cpp

+15-3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include <QSettings>
6262
#include <QEventLoop>
6363
#include <QCoreApplication>
64+
#include <QTextCodec>
6465
#include <QTime>
6566

6667
#ifdef QGISDEBUG
@@ -4376,7 +4377,18 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
43764377
}
43774378
}
43784379

4379-
QgsDebugMsg( "GML (first 2000 bytes):\n" + QString::fromUtf8( mIdentifyResultBodies.value( gmlPart ).left( 2000 ) ) );
4380+
QByteArray gmlByteArray = mIdentifyResultBodies.value( gmlPart );
4381+
QgsDebugMsg( "GML (first 2000 bytes):\n" + gmlByteArray.left( 2000 ) );
4382+
4383+
// QgsGmlSchema.guessSchema() and QgsGml::getFeatures() are using Expat
4384+
// which only accepts UTF-8, UTF-16, ISO-8859-1
4385+
// http://sourceforge.net/p/expat/bugs/498/
4386+
QDomDocument dom;
4387+
dom.setContent( gmlByteArray ); // gets XML encoding
4388+
QTextStream stream( &gmlByteArray );
4389+
stream.setCodec( QTextCodec::codecForName( "UTF-8" ) );
4390+
dom.save( stream, 4, QDomNode::EncodingFromTextStream );
4391+
43804392
QGis::WkbType wkbType;
43814393
QgsGmlSchema gmlSchema;
43824394

@@ -4418,7 +4430,7 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
44184430
else
44194431
{
44204432
// guess from GML
4421-
bool ok = gmlSchema.guessSchema( mIdentifyResultBodies.value( gmlPart ) );
4433+
bool ok = gmlSchema.guessSchema( gmlByteArray );
44224434
if ( ! ok )
44234435
{
44244436
QgsError err = gmlSchema.error();
@@ -4454,7 +4466,7 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
44544466
}
44554467
QgsGml gml( featureTypeName, geometryAttribute, fields );
44564468
// TODO: avoid converting to string and back
4457-
int ret = gml.getFeatures( mIdentifyResultBodies.value( gmlPart ), &wkbType );
4469+
int ret = gml.getFeatures( gmlByteArray, &wkbType );
44584470
#ifdef QGISDEBUG
44594471
QgsDebugMsg( QString( "parsing result = %1" ).arg( ret ) );
44604472
#else

0 commit comments

Comments
 (0)