Skip to content
Permalink
Browse files
Merge pull request #43929 from elpaso/bugfix-gh43849-server-wms-inval…
…id-filter-throws

Server WMS getfeatureinfo: throw on invalid filter
  • Loading branch information
elpaso committed Jun 27, 2021
2 parents 8dde0b1 + cb308b9 commit 856a63a6ec710ab32294c4445578eaae586e90cc
@@ -3031,7 +3031,15 @@ namespace QgsWms
newSubsetString.prepend( filteredLayer->subsetString() );
newSubsetString.prepend( "(" );
}
filteredLayer->setSubsetString( newSubsetString );
if ( ! filteredLayer->setSubsetString( newSubsetString ) )
{
QgsMessageLog::logMessage( QStringLiteral( "Error setting subset string from filter for layer %1, filter: %2" ).arg( layer->name(), newSubsetString ),
QStringLiteral( "Server" ),
Qgis::MessageLevel::Warning );
throw QgsBadRequestException( QgsServiceException::QGIS_InvalidParameterValue,
QStringLiteral( "Filter not valid for layer %1: check the filter syntax and the field names." ).arg( layer->name() ) );

}
}
}

@@ -829,6 +829,20 @@ def testGetFeatureInfoRasterNoData(self):
'test_raster_nodata.qgz',
raw=True)

def test_wrong_filter_throws(self):
"""Test that a wrong FILTER expression throws an InvalidParameterValue exception"""

_, response_body, _ = self.wms_request(
'GetFeatureInfo',
'&layers=testlayer%20%C3%A8%C3%A9&' +
'INFO_FORMAT=text%2Fxml&' +
'width=600&height=400&srs=EPSG%3A3857&' +
'query_layers=testlayer%20%C3%A8%C3%A9&' +
'FEATURE_COUNT=10&FILTER=testlayer%20%C3%A8%C3%A9' +
urllib.parse.quote(':"XXXXXXXXXNAMEXXXXXXX" = \'two\''))

self.assertEqual(response_body.decode('utf8'), '<ServiceExceptionReport xmlns="http://www.opengis.net/ogc" version="1.3.0">\n <ServiceException code="InvalidParameterValue">Filter not valid for layer testlayer èé: check the filter syntax and the field names.</ServiceException>\n</ServiceExceptionReport>\n')


if __name__ == '__main__':
unittest.main()

0 comments on commit 856a63a

Please sign in to comment.