Permalink
Browse files

SLD / Filter encoding: fix escaping of REGEX special characters (fixes

  • Loading branch information...
rouault committed Sep 7, 2018
1 parent b805b5b commit b023c9c5db10260abba86fe2b7c1972d5bf94f45
@@ -52,6 +52,10 @@ char *FLTGetIsLikeComparisonCommonExpression(FilterEncodingNode *psFilterNode)
int nLength=0, i=0, iTmp=0;
/* From http://www.fon.hum.uva.nl/praat/manual/Regular_expressions_1__Special_characters.html */
/* also add double quote because we are within a string */
const char* pszRegexSpecialCharsAndDoubleQuote = "\\^${}[]().*+?|<>-&\"";
if (!psFilterNode || !psFilterNode->pOther || !psFilterNode->psLeftNode || !psFilterNode->psRightNode || !psFilterNode->psRightNode->pszValue)
return NULL;
@@ -97,23 +101,45 @@ char *FLTGetIsLikeComparisonCommonExpression(FilterEncodingNode *psFilterNode)
iTmp++;
}
for (i=0; i<nLength; i++) {
if (pszValue[i] != pszWild[0] && pszValue[i] != pszSingle[0] && pszValue[i] != pszEscape[0]) {
szTmp[iTmp] = pszValue[i];
iTmp++;
szTmp[iTmp] = '\0';
} else if (pszValue[i] == pszSingle[0]) {
if (pszValue[i] == pszSingle[0]) {
szTmp[iTmp] = '.';
iTmp++;
szTmp[iTmp] = '\0';
} else if (pszValue[i] == pszEscape[0]) {
/* The Filter escape character is supposed to only escape the single, wildcard and escape character */
/* As we replace single and wild by regular expression special characters, we indeed */
/* need to escape them */
} else if (pszValue[i] == pszEscape[0] && (pszValue[i+1] == pszSingle[0] || pszValue[i+1] == pszWild[0])) {
szTmp[iTmp] = '\\';
iTmp++;
szTmp[iTmp] = '\0';
/* If the Filter escape character is escaped, only regular-expression-escape-it */
/* if it is indeed a regular expression special character. Otherwise ignore it */
} else if (pszValue[i] == pszEscape[0] && pszValue[i+1] == pszEscape[0]) {
if( strchr(pszRegexSpecialCharsAndDoubleQuote, pszValue[i]) )
{
szTmp[iTmp] = '\\';
iTmp++;
szTmp[iTmp] = '\0';
}
} else if (pszValue[i] == pszWild[0]) {
szTmp[iTmp++] = '.';
szTmp[iTmp++] = '*';
szTmp[iTmp] = '\0';
}
/* Escape regular expressions special characters and double quote */
else if (strchr(pszRegexSpecialCharsAndDoubleQuote, pszValue[i]))
{
szTmp[iTmp] = '\\';
iTmp++;
szTmp[iTmp] = pszValue[i];
iTmp++;
szTmp[iTmp] = '\0';
}
else {
szTmp[iTmp] = pszValue[i];
iTmp++;
szTmp[iTmp] = '\0';
}
}
szTmp[iTmp] = '"';
szTmp[++iTmp] = '\0';
@@ -0,0 +1,3 @@
id,prop,WKT
1,"()[].yxabc","LINESTRING(-67.5725 42,-58.9275 48.5)"
2,"x","LINESTRING(-67.5725 42,-58.9275 48.5)"
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,34 @@
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=test_islike_escaping&amp;OUTPUTFORMAT=XMLSCHEMA">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>-67.572500,42.000000 -58.927500,48.500000</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<ms:test_islike_escaping>
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>-67.572500,42.000000 -58.927500,48.500000</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:msGeometry>
<gml:LineString srsName="EPSG:4326">
<gml:coordinates>-67.572500,42.000000 -58.927500,48.500000 </gml:coordinates>
</gml:LineString>
</ms:msGeometry>
<ms:id>1</ms:id>
<ms:prop>()[].yxabc</ms:prop>
</ms:test_islike_escaping>
</gml:featureMember>
</wfs:FeatureCollection>
@@ -53,6 +53,9 @@
# 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_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>()[]^..x*c</Literal></PropertyIsLike></Filter>" > [RESULT]
#
#
# RUN_PARMS: wfs_filter_200_islike.xml [MAPSERV] [POST]<?xml version="1.0"?><GetFeature service="WFS" version="2.0.0" xmlns:fes="http://www.opengis.net/fes/2.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns="http://www.opengis.net/wfs/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/fes/2.0 http://schemas.opengis.net/filter/2.0/filterAll.xsd http://www.opengis.net/wfs/2.0 http://schemas.opengis.net/wfs/2.0/wfs.xsd http://www.opengis.net/gml/3.2 http://schemas.opengis.net/gml/3.2.1/gml.xsd"><Query typeNames="popplace"><fes:Filter><fes:PropertyIsLike wildCard='*' singleChar='.' escapeChar='!'><fes:ValueReference>NAME</fes:ValueReference><fes:Literal>Syd*</fes:Literal></fes:PropertyIsLike></fes:Filter></Query></GetFeature>[/POST] > [RESULT_DEVERSION]
# Verify PropertyIsLike with logical operators
@@ -355,4 +358,22 @@ LAYER
END
END # Layer
LAYER
NAME test_islike_escaping
DATA test_islike_escaping
METADATA
"wfs_title" "test_islike_escaping"
"wfs_description" "test_islike_escaping"
"gml_include_items" "all"
END
TYPE LINE
STATUS ON
PROJECTION
"init=epsg:4326"
END
DUMP TRUE
END # Layer
END # Map File

0 comments on commit b023c9c

Please sign in to comment.