Skip to content

Commit a73a645

Browse files
authored
Merge pull request #346 from georchestra/csw-get-records-wildcard-fix
Fix: attempt to fix CSW filters with empty escapeChar
2 parents 0115824 + 22b2bef commit a73a645

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

csw-server/src/main/java/org/fao/geonet/kernel/csw/services/getrecords/es/CswFilter2Es.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ protected static String convertLikePattern(PropertyIsLike filter) {
158158
// For example, if the wildcard is % and the escape character is \:
159159
// - in the previous replacement %afr\%ca% becomes *afr\*ca*
160160
// - and with this replacement *afr\*ca* becomes *afr\%ca*
161-
result = result.replaceAll(Pattern.quote(escapeWildcardDefault), wildcardChar);
161+
// Skip if the escapeChar is an empty string, to avoid reverting previous change
162+
if (! StringUtils.isEmpty(filter.getEscape()))
163+
result = result.replaceAll(Pattern.quote(escapeWildcardDefault), wildcardChar);
162164

163165
if (wildcardChar.equals("%")) {
164166
// Escape % for String.format used in SearchController to process the csw filter
@@ -171,7 +173,9 @@ protected static String convertLikePattern(PropertyIsLike filter) {
171173
String escapeSinglecharDefault = filter.getEscape() + "?";
172174

173175
result = result.replaceAll(Pattern.quote(singleChar), "?");
174-
result = result.replaceAll(Pattern.quote(escapeSinglecharDefault), singleChar);
176+
// Skip if the escapeChar is an empty string, to avoid reverting previous change
177+
if (! StringUtils.isEmpty(filter.getEscape()))
178+
result = result.replaceAll(Pattern.quote(escapeSinglecharDefault), singleChar);
175179

176180
if (singleChar.equals("%")) {
177181
result = result.replace( singleChar, "%%");

csw-server/src/test/java/org/fao/geonet/kernel/csw/services/getrecords/es/CswFilter2EsTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,26 @@ void testPropertyIsLike() throws IOException {
195195
assertFilterEquals(expected, input);
196196
}
197197

198+
@Test
199+
void testUuidPropertyIsLike() throws IOException {
200+
201+
final String input =
202+
" <Filter xmlns=\"http://www.opengis.net/ogc\">\n" +
203+
" <PropertyIsLike wildCard=\"%\" singleChar=\"_\" escapeChar=\"\">\n" +
204+
" <PropertyName>dc:identifier</PropertyName>\n" +
205+
" <Literal>%</Literal>\n" +
206+
" </PropertyIsLike>\n" +
207+
" </Filter>\n";
208+
209+
// EXPECTED:
210+
final ObjectNode expected = EsJsonHelper.boolbdr(). //
211+
must(array(queryStringPart("dc:identifier", "*"))). //
212+
filter(queryStringPart()). //
213+
bld();
214+
215+
assertFilterEquals(expected, input);
216+
}
217+
198218
@Test
199219
void testPropertyIsLikeSpecialChars() throws IOException {
200220

0 commit comments

Comments
 (0)