Skip to content

Commit 24737be

Browse files
committed
[BUGFIX][Server] Enhance cleaning propertyname and searching by propertyname
1 parent e7d587f commit 24737be

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/server/services/wfs/qgswfsdescribefeaturetype.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ namespace QgsWfs
263263

264264
//xsd:element
265265
QDomElement attElem = doc.createElement( QStringLiteral( "element" )/*xsd:element*/ );
266-
attElem.setAttribute( QStringLiteral( "name" ), attributeName.replace( ' ', '_' ) );
266+
attElem.setAttribute( QStringLiteral( "name" ), attributeName.replace( ' ', '_' ).replace( cleanTagNameRegExp, QLatin1String( "" ) ) );
267267
QVariant::Type attributeType = fields.at( idx ).type();
268268
if ( attributeType == QVariant::Int )
269269
attElem.setAttribute( QStringLiteral( "type" ), QStringLiteral( "integer" ) );

src/server/services/wfs/qgswfsgetfeature.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,21 @@ namespace QgsWfs
250250
QList<int> idxList;
251251
// build corresponding propertyname
252252
QList<QString> propertynames;
253+
QList<QString> fieldnames;
253254
for ( int idx = 0; idx < fields.count(); ++idx )
254255
{
255-
propertynames.append( fields.field( idx ).name().replace( ' ', '_' ) );
256+
fieldnames.append( fields[idx].name() );
257+
propertynames.append( fields.field( idx ).name().replace( ' ', '_' ).replace( cleanTagNameRegExp, QLatin1String( "" ) ) );
256258
}
257259
QString fieldName;
258260
for ( plstIt = propertyList.begin(); plstIt != propertyList.end(); ++plstIt )
259261
{
260262
fieldName = *plstIt;
261263
int fieldNameIdx = propertynames.indexOf( fieldName );
264+
if ( fieldNameIdx == -1 )
265+
{
266+
fieldNameIdx = fieldnames.indexOf( fieldName );
267+
}
262268
if ( fieldNameIdx > -1 )
263269
{
264270
idxList.append( fieldNameIdx );
@@ -1319,7 +1325,7 @@ namespace QgsWfs
13191325
}
13201326
QString attributeName = fields.at( idx ).name();
13211327

1322-
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( ' ', '_' ) );
1328+
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( ' ', '_' ).replace( cleanTagNameRegExp, QLatin1String( "" ) ) );
13231329
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
13241330
fieldElem.appendChild( fieldText );
13251331
typeNameElement.appendChild( fieldElem );
@@ -1416,7 +1422,7 @@ namespace QgsWfs
14161422
}
14171423
QString attributeName = fields.at( idx ).name();
14181424

1419-
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( ' ', '_' ) );
1425+
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( ' ', '_' ).replace( cleanTagNameRegExp, QLatin1String( "" ) ) );
14201426
QDomText fieldText = doc.createTextNode( featureAttributes[idx].toString() );
14211427
fieldElem.appendChild( fieldText );
14221428
typeNameElement.appendChild( fieldElem );

src/server/services/wfs/qgswfsutils.h

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ namespace QgsWfs
5858
const QString OGC_NAMESPACE = QStringLiteral( "http://www.opengis.net/ogc" );
5959
const QString QGS_NAMESPACE = QStringLiteral( "http://www.qgis.org/gml" );
6060

61+
// Define clean tagName regExp
62+
const QRegExp cleanTagNameRegExp( "(?![\\w\\d\\.-])." );
63+
6164
} // namespace QgsWfs
6265

6366
#endif

0 commit comments

Comments
 (0)