Skip to content

Commit 0e0146d

Browse files
authoredJan 22, 2019
Merge pull request #8924 from elpaso/bugfix-20927-server_exp_filter
Server WFS EXP_FILTER bugfixes
2 parents ee34431 + 9b7e191 commit 0e0146d

11 files changed

+183
-18
lines changed
 

‎src/server/services/wfs/qgswfsgetfeature.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -673,16 +673,13 @@ namespace QgsWfs
673673
{
674674
if ( filter->hasParserError() )
675675
{
676-
QgsMessageLog::logMessage( filter->parserErrorString() );
676+
throw QgsRequestNotWellFormedException( QStringLiteral( "The EXP_FILTER expression has errors: %1" ).arg( filter->parserErrorString() ) );
677677
}
678-
else
678+
if ( filter->needsGeometry() )
679679
{
680-
if ( filter->needsGeometry() )
681-
{
682-
query.featureRequest.setFlags( QgsFeatureRequest::NoFlags );
683-
}
684-
query.featureRequest.setFilterExpression( filter->expression() );
680+
query.featureRequest.setFlags( QgsFeatureRequest::NoFlags );
685681
}
682+
query.featureRequest.setFilterExpression( filter->expression() );
686683
}
687684
}
688685
}

‎src/server/services/wfs/qgswfsparameters.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,23 @@ namespace QgsWfs
7676
if ( val.isEmpty() )
7777
return theList;
7878

79-
QRegExp rx( exp );
80-
if ( rx.indexIn( val, 0 ) == -1 )
81-
{
79+
if ( exp.isEmpty() )
8280
theList << val;
83-
}
8481
else
8582
{
86-
int pos = 0;
87-
while ( ( pos = rx.indexIn( val, pos ) ) != -1 )
83+
QRegExp rx( exp );
84+
if ( rx.indexIn( val, 0 ) == -1 )
85+
{
86+
theList << val;
87+
}
88+
else
8889
{
89-
theList << rx.cap( 1 );
90-
pos += rx.matchedLength();
90+
int pos = 0;
91+
while ( ( pos = rx.indexIn( val, pos ) ) != -1 )
92+
{
93+
theList << rx.cap( 1 );
94+
pos += rx.matchedLength();
95+
}
9196
}
9297
}
9398

@@ -332,7 +337,7 @@ namespace QgsWfs
332337

333338
QStringList QgsWfsParameters::expFilters() const
334339
{
335-
return mWfsParameters[ QgsWfsParameter::EXP_FILTER ].toStringListWithExp();
340+
return mWfsParameters[ QgsWfsParameter::EXP_FILTER ].toStringListWithExp( QString( ) );
336341
}
337342

338343
QString QgsWfsParameters::geometryNameAsString() const

‎src/server/services/wfs/qgswfsparameters.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace QgsWfs
8383

8484
/**
8585
* Converts the parameter into a list of string.
86-
* \param exp The expression to use for splitting
86+
* \param exp The expression to use for splitting, pass an empty string to avoid splitting
8787
* \returns A list of strings
8888
* \throws QgsBadRequestException Invalid parameter exception
8989
*/

‎tests/src/python/test_qgsserver_wfs.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@
4141

4242

4343
class TestQgsServerWFS(QgsServerTestBase):
44-
4544
"""QGIS Server WFS Tests"""
4645

46+
# Set to True in child classes to re-generate reference files for this class
47+
#regenerate_reference = True
48+
4749
def wfs_request_compare(self, request, version='', extra_query_string='', reference_base_name=None):
4850
project = self.testdata_path + "test_project_wfs.qgs"
4951
assert os.path.exists(project), "Project file not found: " + project
@@ -367,6 +369,22 @@ def test_getFeatureFeatureId(self):
367369
"""Test GetFeature with featureid"""
368370
self.wfs_request_compare("GetFeature", '1.0.0', "SRSNAME=EPSG:4326&TYPENAME=testlayer&FEATUREID=testlayer.0", 'wfs_getFeature_1_0_0_featureid_0')
369371

372+
def test_getFeature_EXP_FILTER_regression_20927(self):
373+
"""Test expressions with EXP_FILTER"""
374+
375+
self.wfs_request_compare("GetFeature", '1.0.0', "SRSNAME=EPSG:4326&TYPENAME=testlayer&FEATUREID=testlayer.0&EXP_FILTER=\"name\"='one'", 'wfs_getFeature_1_0_0_EXP_FILTER_FID_one')
376+
# Note that FEATUREID takes precedence over EXP_FILTER and the filter is completely ignored when FEATUREID is set
377+
self.wfs_request_compare("GetFeature", '1.0.0', "SRSNAME=EPSG:4326&TYPENAME=testlayer&FEATUREID=testlayer.0&EXP_FILTER=\"name\"='two'", 'wfs_getFeature_1_0_0_EXP_FILTER_FID_one')
378+
self.wfs_request_compare("GetFeature", '1.0.0', "SRSNAME=EPSG:4326&TYPENAME=testlayer&EXP_FILTER=\"name\"='two'", 'wfs_getFeature_1_0_0_EXP_FILTER_two')
379+
self.wfs_request_compare("GetFeature", '1.0.0', "SRSNAME=EPSG:4326&TYPENAME=testlayer&EXP_FILTER=\"name\"=concat('tw', 'o')", 'wfs_getFeature_1_0_0_EXP_FILTER_two')
380+
# Syntax ok but function does not exist
381+
self.wfs_request_compare("GetFeature", '1.0.0', "SRSNAME=EPSG:4326&TYPENAME=testlayer&EXP_FILTER=\"name\"=invalid_expression('tw', 'o')", 'wfs_getFeature_1_0_0_EXP_FILTER_invalid_expression')
382+
# Syntax error in exp
383+
self.wfs_request_compare("GetFeature", '1.0.0', "SRSNAME=EPSG:4326&TYPENAME=testlayer&EXP_FILTER=\"name\"=concat('tw, 'o')", 'wfs_getFeature_1_0_0_EXP_FILTER_syntax_error')
384+
# BBOX gml expressions
385+
self.wfs_request_compare("GetFeature", '1.0.0', "SRSNAME=EPSG:4326&TYPENAME=testlayer&EXP_FILTER=intersects($geometry, geom_from_gml('<gml:Box> <gml:coordinates cs=\",\" ts=\" \">8.20344750430995617,44.9013881888184514 8.20347909100379269,44.90140004005827024</gml:coordinates></gml:Box>'))", 'wfs_getFeature_1_0_0_EXP_FILTER_gml_bbox_three')
386+
self.wfs_request_compare("GetFeature", '1.0.0', "SRSNAME=EPSG:4326&TYPENAME=testlayer&EXP_FILTER=intersects($geometry, geom_from_gml('<gml:Box> <gml:coordinates cs=\",\" ts=\" \">8.20348458304175665,44.90147459621791626 8.20351616973559317,44.9014864474577351</gml:coordinates></gml:Box>'))", 'wfs_getFeature_1_0_0_EXP_FILTER_gml_bbox_one')
387+
370388

371389
if __name__ == '__main__':
372390
unittest.main()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Content-Type: text/xml; subtype=gml/2.1.2; charset=utf-8
2+
3+
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://www.qgis.org/gml ?MAP=/home/ale/dev/QGIS/tests/testdata/qgis_server/test_project_wfs.qgs&amp;SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=testlayer&amp;OUTPUTFORMAT=XMLSCHEMA">
4+
<gml:boundedBy>
5+
<gml:Box srsName="EPSG:4326">
6+
<gml:coordinates cs="," ts=" ">8.20345931,44.90139484 8.20354699,44.90148253</gml:coordinates>
7+
</gml:Box>
8+
</gml:boundedBy>
9+
<gml:featureMember>
10+
<qgs:testlayer fid="testlayer.0">
11+
<gml:boundedBy>
12+
<gml:Box srsName="EPSG:4326">
13+
<gml:coordinates cs="," ts=" ">8.20349634,44.90148253 8.20349634,44.90148253</gml:coordinates>
14+
</gml:Box>
15+
</gml:boundedBy>
16+
<qgs:geometry>
17+
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
18+
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20349634,44.90148253</coordinates>
19+
</Point>
20+
</qgs:geometry>
21+
<qgs:id>1</qgs:id>
22+
<qgs:name>one</qgs:name>
23+
<qgs:utf8nameè>one èé</qgs:utf8nameè>
24+
</qgs:testlayer>
25+
</gml:featureMember>
26+
</wfs:FeatureCollection>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Content-Type: text/xml; subtype=gml/2.1.2; charset=utf-8
2+
3+
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://www.qgis.org/gml ?MAP=/home/ale/dev/QGIS/tests/testdata/qgis_server/test_project_wfs.qgs&amp;SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=testlayer&amp;OUTPUTFORMAT=XMLSCHEMA">
4+
<gml:boundedBy>
5+
<gml:Box srsName="EPSG:4326">
6+
<gml:coordinates cs="," ts=" ">8.20345931,44.90139484 8.20354699,44.90148253</gml:coordinates>
7+
</gml:Box>
8+
</gml:boundedBy>
9+
<gml:featureMember>
10+
<qgs:testlayer fid="testlayer.0">
11+
<gml:boundedBy>
12+
<gml:Box srsName="EPSG:4326">
13+
<gml:coordinates cs="," ts=" ">8.20349634,44.90148253 8.20349634,44.90148253</gml:coordinates>
14+
</gml:Box>
15+
</gml:boundedBy>
16+
<qgs:geometry>
17+
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
18+
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20349634,44.90148253</coordinates>
19+
</Point>
20+
</qgs:geometry>
21+
<qgs:id>1</qgs:id>
22+
<qgs:name>one</qgs:name>
23+
<qgs:utf8nameè>one èé</qgs:utf8nameè>
24+
</qgs:testlayer>
25+
</gml:featureMember>
26+
</wfs:FeatureCollection>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Content-Type: text/xml; subtype=gml/2.1.2; charset=utf-8
2+
3+
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://www.qgis.org/gml ?MAP=/home/ale/dev/QGIS/tests/testdata/qgis_server/test_project_wfs.qgs&amp;SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=testlayer&amp;OUTPUTFORMAT=XMLSCHEMA">
4+
<gml:boundedBy>
5+
<gml:Box srsName="EPSG:4326">
6+
<gml:coordinates cs="," ts=" ">8.20345931,44.90139484 8.20354699,44.90148253</gml:coordinates>
7+
</gml:Box>
8+
</gml:boundedBy>
9+
<gml:featureMember>
10+
<qgs:testlayer fid="testlayer.2">
11+
<gml:boundedBy>
12+
<gml:Box srsName="EPSG:4326">
13+
<gml:coordinates cs="," ts=" ">8.20345931,44.90139484 8.20345931,44.90139484</gml:coordinates>
14+
</gml:Box>
15+
</gml:boundedBy>
16+
<qgs:geometry>
17+
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
18+
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20345931,44.90139484</coordinates>
19+
</Point>
20+
</qgs:geometry>
21+
<qgs:id>3</qgs:id>
22+
<qgs:name>three</qgs:name>
23+
<qgs:utf8nameè>three èé↓</qgs:utf8nameè>
24+
</qgs:testlayer>
25+
</gml:featureMember>
26+
</wfs:FeatureCollection>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Content-Length: 229
2+
Content-Type: text/xml; charset=utf-8
3+
4+
<ServiceExceptionReport xmlns="http://www.opengis.net/ogc" version="1.2.0">
5+
<ServiceException code="RequestNotWellFormed">The EXP_FILTER expression has errors:
6+
Function is not known</ServiceException>
7+
</ServiceExceptionReport>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Content-Length: 320
2+
Content-Type: text/xml; charset=utf-8
3+
4+
<ServiceExceptionReport xmlns="http://www.opengis.net/ogc" version="1.2.0">
5+
<ServiceException code="RequestNotWellFormed">The EXP_FILTER expression has errors:
6+
syntax error, unexpected NAME, expecting COMMA or ')'
7+
syntax error, unexpected Unknown_CHARACTER, expecting $end</ServiceException>
8+
</ServiceExceptionReport>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Content-Type: text/xml; subtype=gml/2.1.2; charset=utf-8
2+
3+
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://www.qgis.org/gml ?MAP=/home/ale/dev/QGIS/tests/testdata/qgis_server/test_project_wfs.qgs&amp;SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=testlayer&amp;OUTPUTFORMAT=XMLSCHEMA">
4+
<gml:boundedBy>
5+
<gml:Box srsName="EPSG:4326">
6+
<gml:coordinates cs="," ts=" ">8.20345931,44.90139484 8.20354699,44.90148253</gml:coordinates>
7+
</gml:Box>
8+
</gml:boundedBy>
9+
<gml:featureMember>
10+
<qgs:testlayer fid="testlayer.1">
11+
<gml:boundedBy>
12+
<gml:Box srsName="EPSG:4326">
13+
<gml:coordinates cs="," ts=" ">8.20354699,44.90143568 8.20354699,44.90143568</gml:coordinates>
14+
</gml:Box>
15+
</gml:boundedBy>
16+
<qgs:geometry>
17+
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
18+
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20354699,44.90143568</coordinates>
19+
</Point>
20+
</qgs:geometry>
21+
<qgs:id>2</qgs:id>
22+
<qgs:name>two</qgs:name>
23+
<qgs:utf8nameè>two àò</qgs:utf8nameè>
24+
</qgs:testlayer>
25+
</gml:featureMember>
26+
</wfs:FeatureCollection>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Content-Type: text/xml; subtype=gml/2.1.2; charset=utf-8
2+
3+
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ogc="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml" xmlns:ows="http://www.opengis.net/ows" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:qgs="http://www.qgis.org/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/wfs.xsd http://www.qgis.org/gml ?MAP=/home/ale/dev/QGIS/tests/testdata/qgis_server/test_project_wfs.qgs&amp;SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=testlayer&amp;OUTPUTFORMAT=XMLSCHEMA">
4+
<gml:boundedBy>
5+
<gml:Box srsName="EPSG:4326">
6+
<gml:coordinates cs="," ts=" ">8.20345931,44.90139484 8.20354699,44.90148253</gml:coordinates>
7+
</gml:Box>
8+
</gml:boundedBy>
9+
<gml:featureMember>
10+
<qgs:testlayer fid="testlayer.0">
11+
<gml:boundedBy>
12+
<gml:Box srsName="EPSG:4326">
13+
<gml:coordinates cs="," ts=" ">8.20349634,44.90148253 8.20349634,44.90148253</gml:coordinates>
14+
</gml:Box>
15+
</gml:boundedBy>
16+
<qgs:geometry>
17+
<Point xmlns="http://www.opengis.net/gml" srsName="EPSG:4326">
18+
<coordinates xmlns="http://www.opengis.net/gml" cs="," ts=" ">8.20349634,44.90148253</coordinates>
19+
</Point>
20+
</qgs:geometry>
21+
<qgs:id>1</qgs:id>
22+
<qgs:name>one</qgs:name>
23+
<qgs:utf8nameè>one èé</qgs:utf8nameè>
24+
</qgs:testlayer>
25+
</gml:featureMember>
26+
</wfs:FeatureCollection>

0 commit comments

Comments
 (0)
Please sign in to comment.