Skip to content

Commit

Permalink
FLTGetIsLikeComparisonCommonExpression(): add terminating '$' at end …
Browse files Browse the repository at this point in the history
…of regular expression (fixes #5825)
  • Loading branch information
rouault committed Jun 21, 2019
1 parent ff0491b commit 6f0885e
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 4 deletions.
6 changes: 5 additions & 1 deletion mapogcfiltercommon.c
Expand Up @@ -93,7 +93,7 @@ char *FLTGetIsLikeComparisonCommonExpression(FilterEncodingNode *psFilterNode)
pszValue = psFilterNode->psRightNode->pszValue;
nLength = strlen(pszValue);
/* The 4 factor is in case of \. See below */
if( 1 + 4 * nLength + 1 + 1 >= sizeof(szTmp) )
if( 1 + 4 * nLength + 1 + 1 + 1 >= sizeof(szTmp) )
return NULL;

iTmp =0;
Expand Down Expand Up @@ -163,6 +163,10 @@ char *FLTGetIsLikeComparisonCommonExpression(FilterEncodingNode *psFilterNode)
szTmp[iTmp] = '\0';
}
}
if (nLength > 0) {
szTmp[iTmp]= '$';
iTmp++;
}
szTmp[iTmp] = '"';
szTmp[++iTmp] = '\0';
#if 0
Expand Down
10 changes: 7 additions & 3 deletions mapogr.cpp
Expand Up @@ -1934,12 +1934,14 @@ char *msOGRGetToken(layerObj* layer, tokenListNodeObjPtr *node) {
}
else if (c == '.')
c = wild_one;

if (i == 0 && c == '^') {
else if (i == 0 && c == '^') {
i++;
continue;
}

else if( c == '$' && c_next == 0 ) {
break;
}

re[j++] = c;
i++;

Expand Down Expand Up @@ -3643,6 +3645,8 @@ static std::string msOGRTranslatePartialInternal(layerObj* layer,
{
if( i == 0 && expr->m_aoChildren[1]->m_osVal[i] == '^' )
continue;
if( i == nSize-1 && expr->m_aoChildren[1]->m_osVal[i] == '$' )
break;
if( expr->m_aoChildren[1]->m_osVal[i] == '.' )
{
if( i+1<nSize &&
Expand Down
@@ -0,0 +1,16 @@
Content-Type: text/xml; charset=UTF-8

<?xml version='1.0' encoding="UTF-8" ?>
<wfs:FeatureCollection
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:gml="http://www.opengis.net/gml"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://ogc.dmsolutions.ca/wfs/1.0.0/WFS-basic.xsd
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">
<gml:boundedBy>
<gml:null>missing</gml:null>
</gml:boundedBy>
</wfs:FeatureCollection>

@@ -0,0 +1,49 @@
Content-Type: text/xml; charset=UTF-8

<?xml version='1.0' encoding="UTF-8" ?>
<wfs:FeatureCollection
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:gml="http://www.opengis.net/gml"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://ogc.dmsolutions.ca/wfs/1.0.0/WFS-basic.xsd
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">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>-60.214963,46.123322 -60.214963,46.123322</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<ms:popplace>
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>-60.214963,46.123322 -60.214963,46.123322</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:msGeometry>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-60.214963,46.123322</gml:coordinates>
</gml:Point>
</ms:msGeometry>
<ms:AREA>0.000</ms:AREA>
<ms:PERIMETER>0.000</ms:PERIMETER>
<ms:POPPLACE_>391</ms:POPPLACE_>
<ms:POPPLACE_I>4</ms:POPPLACE_I>
<ms:UNIQUE_KEY>CBLGX</ms:UNIQUE_KEY>
<ms:NAME>Sydney</ms:NAME>
<ms:NAME_E></ms:NAME_E>
<ms:NAME_F></ms:NAME_F>
<ms:UNIQUE_K_1></ms:UNIQUE_K_1>
<ms:UNIQUE_K_2></ms:UNIQUE_K_2>
<ms:REG_CODE>12</ms:REG_CODE>
<ms:NTS50>011K01</ms:NTS50>
<ms:LAT>460900</ms:LAT>
<ms:LONG>601100</ms:LONG>
<ms:SGC_CODE>1217014</ms:SGC_CODE>
<ms:CAPITAL>0</ms:CAPITAL>
<ms:POP_RANGE>4</ms:POP_RANGE>
</ms:popplace>
</gml:featureMember>
</wfs:FeatureCollection>

@@ -0,0 +1,16 @@
Content-Type: text/xml; charset=UTF-8

<?xml version='1.0' encoding="UTF-8" ?>
<wfs:FeatureCollection
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:gml="http://www.opengis.net/gml"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://ogc.dmsolutions.ca/wfs/1.0.0/WFS-basic.xsd
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">
<gml:boundedBy>
<gml:null>missing</gml:null>
</gml:boundedBy>
</wfs:FeatureCollection>

@@ -0,0 +1,50 @@
Content-Type: text/xml; charset=UTF-8

<?xml version='1.0' encoding="UTF-8" ?>
<wfs:FeatureCollection
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:gml="http://www.opengis.net/gml"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://ogc.dmsolutions.ca/wfs/1.0.0/WFS-basic.xsd
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">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>-60.214963,46.123322 -60.214963,46.123322</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<ms:popplace>
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>-60.214963,46.123322 -60.214963,46.123322</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:msGeometry>
<gml:Point srsName="EPSG:4326">
<gml:coordinates>-60.214963,46.123322</gml:coordinates>
</gml:Point>
</ms:msGeometry>
<ms:gid>24</ms:gid>
<ms:area>0</ms:area>
<ms:perimeter>0</ms:perimeter>
<ms:popplace_>391</ms:popplace_>
<ms:popplace_i>4</ms:popplace_i>
<ms:unique_key>CBLGX</ms:unique_key>
<ms:name>Sydney</ms:name>
<ms:name_e></ms:name_e>
<ms:name_f></ms:name_f>
<ms:unique_k_1></ms:unique_k_1>
<ms:unique_k_2></ms:unique_k_2>
<ms:reg_code>12</ms:reg_code>
<ms:nts50>011K01</ms:nts50>
<ms:lat>460900</ms:lat>
<ms:long>601100</ms:long>
<ms:sgc_code>1217014</ms:sgc_code>
<ms:capital>0</ms:capital>
<ms:pop_range>4</ms:pop_range>
</ms:popplace>
</gml:featureMember>
</wfs:FeatureCollection>

4 changes: 4 additions & 0 deletions msautotest/wxs/wfs_filter.map
Expand Up @@ -53,6 +53,10 @@
# Verify PropertyIsLike
# 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]
#
# 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]
#
# 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]
#
# 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]
#
# Again but use as an escape character the regexp escape character
Expand Down
4 changes: 4 additions & 0 deletions msautotest/wxs/wfs_filter_postgis.map
Expand Up @@ -46,6 +46,10 @@
# Verify PropertyIsLike
# 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]
#
# 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]
#
# 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]
#
#
# Verify PropertyIsLike with logical operators
# 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]
Expand Down

0 comments on commit 6f0885e

Please sign in to comment.