Skip to content

Commit eea166a

Browse files
committed
FLTGetIsLikeComparisonCommonExpression(): add terminating '$' at end of regular expression (fixes #5825)
1 parent 139ed5a commit eea166a

8 files changed

+151
-4
lines changed

mapogcfiltercommon.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ char *FLTGetIsLikeComparisonCommonExpression(FilterEncodingNode *psFilterNode)
9393
pszValue = psFilterNode->psRightNode->pszValue;
9494
nLength = strlen(pszValue);
9595
/* The 4 factor is in case of \. See below */
96-
if( 1 + 4 * nLength + 1 + 1 >= sizeof(szTmp) )
96+
if( 1 + 4 * nLength + 1 + 1 + 1 >= sizeof(szTmp) )
9797
return NULL;
9898

9999
iTmp =0;
@@ -163,6 +163,10 @@ char *FLTGetIsLikeComparisonCommonExpression(FilterEncodingNode *psFilterNode)
163163
szTmp[iTmp] = '\0';
164164
}
165165
}
166+
if (nLength > 0) {
167+
szTmp[iTmp]= '$';
168+
iTmp++;
169+
}
166170
szTmp[iTmp] = '"';
167171
szTmp[++iTmp] = '\0';
168172
#if 0

mapogr.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,12 +1934,14 @@ char *msOGRGetToken(layerObj* layer, tokenListNodeObjPtr *node) {
19341934
}
19351935
else if (c == '.')
19361936
c = wild_one;
1937-
1938-
if (i == 0 && c == '^') {
1937+
else if (i == 0 && c == '^') {
19391938
i++;
19401939
continue;
19411940
}
1942-
1941+
else if( c == '$' && c_next == 0 ) {
1942+
break;
1943+
}
1944+
19431945
re[j++] = c;
19441946
i++;
19451947

@@ -3643,6 +3645,8 @@ static std::string msOGRTranslatePartialInternal(layerObj* layer,
36433645
{
36443646
if( i == 0 && expr->m_aoChildren[1]->m_osVal[i] == '^' )
36453647
continue;
3648+
if( i == nSize-1 && expr->m_aoChildren[1]->m_osVal[i] == '$' )
3649+
break;
36463650
if( expr->m_aoChildren[1]->m_osVal[i] == '.' )
36473651
{
36483652
if( i+1<nSize &&
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Content-Type: text/xml; charset=UTF-8
2+
3+
<?xml version='1.0' encoding="UTF-8" ?>
4+
<wfs:FeatureCollection
5+
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
6+
xmlns:wfs="http://www.opengis.net/wfs"
7+
xmlns:gml="http://www.opengis.net/gml"
8+
xmlns:ogc="http://www.opengis.net/ogc"
9+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:schemaLocation="http://www.opengis.net/wfs http://ogc.dmsolutions.ca/wfs/1.0.0/WFS-basic.xsd
11+
http://mapserver.gis.umn.edu/mapserver http://localhost/path/to/wfs_simple?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=popplace&amp;OUTPUTFORMAT=XMLSCHEMA">
12+
<gml:boundedBy>
13+
<gml:null>missing</gml:null>
14+
</gml:boundedBy>
15+
</wfs:FeatureCollection>
16+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Content-Type: text/xml; charset=UTF-8
2+
3+
<?xml version='1.0' encoding="UTF-8" ?>
4+
<wfs:FeatureCollection
5+
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
6+
xmlns:wfs="http://www.opengis.net/wfs"
7+
xmlns:gml="http://www.opengis.net/gml"
8+
xmlns:ogc="http://www.opengis.net/ogc"
9+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:schemaLocation="http://www.opengis.net/wfs http://ogc.dmsolutions.ca/wfs/1.0.0/WFS-basic.xsd
11+
http://mapserver.gis.umn.edu/mapserver http://localhost/path/to/wfs_simple?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=popplace&amp;OUTPUTFORMAT=XMLSCHEMA">
12+
<gml:boundedBy>
13+
<gml:Box srsName="EPSG:4326">
14+
<gml:coordinates>-60.214963,46.123322 -60.214963,46.123322</gml:coordinates>
15+
</gml:Box>
16+
</gml:boundedBy>
17+
<gml:featureMember>
18+
<ms:popplace>
19+
<gml:boundedBy>
20+
<gml:Box srsName="EPSG:4326">
21+
<gml:coordinates>-60.214963,46.123322 -60.214963,46.123322</gml:coordinates>
22+
</gml:Box>
23+
</gml:boundedBy>
24+
<ms:msGeometry>
25+
<gml:Point srsName="EPSG:4326">
26+
<gml:coordinates>-60.214963,46.123322</gml:coordinates>
27+
</gml:Point>
28+
</ms:msGeometry>
29+
<ms:AREA>0.000</ms:AREA>
30+
<ms:PERIMETER>0.000</ms:PERIMETER>
31+
<ms:POPPLACE_>391</ms:POPPLACE_>
32+
<ms:POPPLACE_I>4</ms:POPPLACE_I>
33+
<ms:UNIQUE_KEY>CBLGX</ms:UNIQUE_KEY>
34+
<ms:NAME>Sydney</ms:NAME>
35+
<ms:NAME_E></ms:NAME_E>
36+
<ms:NAME_F></ms:NAME_F>
37+
<ms:UNIQUE_K_1></ms:UNIQUE_K_1>
38+
<ms:UNIQUE_K_2></ms:UNIQUE_K_2>
39+
<ms:REG_CODE>12</ms:REG_CODE>
40+
<ms:NTS50>011K01</ms:NTS50>
41+
<ms:LAT>460900</ms:LAT>
42+
<ms:LONG>601100</ms:LONG>
43+
<ms:SGC_CODE>1217014</ms:SGC_CODE>
44+
<ms:CAPITAL>0</ms:CAPITAL>
45+
<ms:POP_RANGE>4</ms:POP_RANGE>
46+
</ms:popplace>
47+
</gml:featureMember>
48+
</wfs:FeatureCollection>
49+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Content-Type: text/xml; charset=UTF-8
2+
3+
<?xml version='1.0' encoding="UTF-8" ?>
4+
<wfs:FeatureCollection
5+
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
6+
xmlns:wfs="http://www.opengis.net/wfs"
7+
xmlns:gml="http://www.opengis.net/gml"
8+
xmlns:ogc="http://www.opengis.net/ogc"
9+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:schemaLocation="http://www.opengis.net/wfs http://ogc.dmsolutions.ca/wfs/1.0.0/WFS-basic.xsd
11+
http://mapserver.gis.umn.edu/mapserver http://localhost/path/to/wfs_simple?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=popplace&amp;OUTPUTFORMAT=XMLSCHEMA">
12+
<gml:boundedBy>
13+
<gml:null>missing</gml:null>
14+
</gml:boundedBy>
15+
</wfs:FeatureCollection>
16+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Content-Type: text/xml; charset=UTF-8
2+
3+
<?xml version='1.0' encoding="UTF-8" ?>
4+
<wfs:FeatureCollection
5+
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
6+
xmlns:wfs="http://www.opengis.net/wfs"
7+
xmlns:gml="http://www.opengis.net/gml"
8+
xmlns:ogc="http://www.opengis.net/ogc"
9+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:schemaLocation="http://www.opengis.net/wfs http://ogc.dmsolutions.ca/wfs/1.0.0/WFS-basic.xsd
11+
http://mapserver.gis.umn.edu/mapserver http://localhost/path/to/wfs_simple?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=popplace&amp;OUTPUTFORMAT=XMLSCHEMA">
12+
<gml:boundedBy>
13+
<gml:Box srsName="EPSG:4326">
14+
<gml:coordinates>-60.214963,46.123322 -60.214963,46.123322</gml:coordinates>
15+
</gml:Box>
16+
</gml:boundedBy>
17+
<gml:featureMember>
18+
<ms:popplace>
19+
<gml:boundedBy>
20+
<gml:Box srsName="EPSG:4326">
21+
<gml:coordinates>-60.214963,46.123322 -60.214963,46.123322</gml:coordinates>
22+
</gml:Box>
23+
</gml:boundedBy>
24+
<ms:msGeometry>
25+
<gml:Point srsName="EPSG:4326">
26+
<gml:coordinates>-60.214963,46.123322</gml:coordinates>
27+
</gml:Point>
28+
</ms:msGeometry>
29+
<ms:gid>24</ms:gid>
30+
<ms:area>0</ms:area>
31+
<ms:perimeter>0</ms:perimeter>
32+
<ms:popplace_>391</ms:popplace_>
33+
<ms:popplace_i>4</ms:popplace_i>
34+
<ms:unique_key>CBLGX</ms:unique_key>
35+
<ms:name>Sydney</ms:name>
36+
<ms:name_e></ms:name_e>
37+
<ms:name_f></ms:name_f>
38+
<ms:unique_k_1></ms:unique_k_1>
39+
<ms:unique_k_2></ms:unique_k_2>
40+
<ms:reg_code>12</ms:reg_code>
41+
<ms:nts50>011K01</ms:nts50>
42+
<ms:lat>460900</ms:lat>
43+
<ms:long>601100</ms:long>
44+
<ms:sgc_code>1217014</ms:sgc_code>
45+
<ms:capital>0</ms:capital>
46+
<ms:pop_range>4</ms:pop_range>
47+
</ms:popplace>
48+
</gml:featureMember>
49+
</wfs:FeatureCollection>
50+

msautotest/wxs/wfs_filter.map

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
# Verify PropertyIsLike
5454
# RUN_PARMS: wfs_filter_islike.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=popplace&FILTER=<Filter><PropertyIsLike+wildCard='*'+singleChar='.'+escape='!'><PropertyName>NAME</PropertyName><Literal>Syd*</Literal></PropertyIsLike></Filter>" > [RESULT]
5555
#
56+
# RUN_PARMS: wfs_filter_islike_no_ending_wildcard_empty_resultset.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=popplace&FILTER=<Filter><PropertyIsLike+wildCard='*'+singleChar='.'+escape='!'><PropertyName>NAME</PropertyName><Literal>Syd</Literal></PropertyIsLike></Filter>" > [RESULT]
57+
#
58+
# RUN_PARMS: wfs_filter_islike_no_ending_wildcard_non_empty_resultset.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=popplace&FILTER=<Filter><PropertyIsLike+wildCard='*'+singleChar='.'+escape='!'><PropertyName>NAME</PropertyName><Literal>Sydney</Literal></PropertyIsLike></Filter>" > [RESULT]
59+
#
5660
# RUN_PARMS: wfs_filter_islike_escaping.xml [MAPSERV] QUERY_STRING='map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=test_islike_escaping&FILTER=<Filter><PropertyIsLike+wildCard="*"+singleChar="."+escape="^"><PropertyName>prop</PropertyName><Literal>\^^${}[]()^.^*%2B-?|"a.*e</Literal></PropertyIsLike></Filter>' > [RESULT]
5761
#
5862
# Again but use as an escape character the regexp escape character

msautotest/wxs/wfs_filter_postgis.map

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
# Verify PropertyIsLike
4747
# RUN_PARMS: wfs_filter_postgis_islike.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=popplace&FILTER=<Filter><PropertyIsLike+wildCard='*'+singleChar='.'+escape='!'><PropertyName>name</PropertyName><Literal>Syd*</Literal></PropertyIsLike></Filter>" > [RESULT]
4848
#
49+
# RUN_PARMS: wfs_filter_postgis_islike_no_ending_wildcard_empty_resultset.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=popplace&FILTER=<Filter><PropertyIsLike+wildCard='*'+singleChar='.'+escape='!'><PropertyName>name</PropertyName><Literal>Syd</Literal></PropertyIsLike></Filter>" > [RESULT]
50+
#
51+
# RUN_PARMS: wfs_filter_postgis_islike_no_ending_wildcard_non_empty_resultset.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=popplace&FILTER=<Filter><PropertyIsLike+wildCard='*'+singleChar='.'+escape='!'><PropertyName>name</PropertyName><Literal>Sydney</Literal></PropertyIsLike></Filter>" > [RESULT]
52+
#
4953
#
5054
# Verify PropertyIsLike with logical operators
5155
# RUN_PARMS: wfs_filter_postgis_islike_logical.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=popplace&FILTER=<Filter><AND><PropertyIsLike+wildCard='*'+singleChar='.'+escape='!'><PropertyName>name</PropertyName><Literal>Syd*</Literal></PropertyIsLike><PropertyIsLike+wildCard='*'+singleChar='.'+escape='!'><PropertyName>pop_range</PropertyName><Literal>3</Literal></PropertyIsLike></AND></Filter>" > [RESULT]

0 commit comments

Comments
 (0)