Skip to content

Commit

Permalink
[WFS provider] Be robust to field names ending with spaces in Describ…
Browse files Browse the repository at this point in the history
…eFeatureType

Fixes #3426
  • Loading branch information
rouault committed Oct 6, 2016
1 parent 4169360 commit fb50a3e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/providers/wfs/qgswfsprovider.cpp
Expand Up @@ -1246,8 +1246,15 @@ bool QgsWFSProvider::readAttributesFromSchema( QDomDocument& schemaDoc,
for ( int i = 0; i < attributeNodeList.size(); ++i )
{
QDomElement attributeElement = attributeNodeList.at( i ).toElement();

//attribute name
QString name = attributeElement.attribute( "name" );
// Some servers like http://ogi.state.ok.us/geoserver/wfs on layer ogi:doq_centroids
// return attribute names padded with spaces. See http://hub.qgis.org/issues/3426
// I'm not completely sure how legal this
// is but this validates with Xerces 3.1, and its schema analyzer does also the trimming.
name = name.trimmed();

//attribute type
QString type = attributeElement.attribute( "type" );
if ( type.isEmpty() )
Expand Down
3 changes: 2 additions & 1 deletion tests/src/python/test_provider_wfs.py
Expand Up @@ -111,7 +111,8 @@ def setUpClass(cls):
<xsd:complexContent>
<xsd:extension base="gml:AbstractFeatureType">
<xsd:sequence>
<xsd:element maxOccurs="1" minOccurs="0" name="pk" nillable="true" type="xsd:long"/>
<!-- add a trailing space to the name to test http://hub.qgis.org/issues/3426 -->
<xsd:element maxOccurs="1" minOccurs="0" name="pk " nillable="true" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="cnt" nillable="true" type="xsd:long"/>
<xsd:element maxOccurs="1" minOccurs="0" name="name" nillable="true" type="xsd:string"/>
<xsd:element maxOccurs="1" minOccurs="0" name="name2" nillable="true" type="xsd:string"/>
Expand Down

0 comments on commit fb50a3e

Please sign in to comment.