[2935] Escape "%" in like expression
This commit is contained in:
parent
281596d5f2
commit
a1fbeeacaa
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
type: fix
|
||||
issue: 2935
|
||||
jira: SMILE-3022
|
||||
title: "No resource returned when search with percent sign. Problem is now fixed"
|
|
@ -225,15 +225,15 @@ public class StringPredicateBuilder extends BaseSearchParamPredicateBuilder {
|
|||
}
|
||||
|
||||
public static String createLeftAndRightMatchLikeExpression(String likeExpression) {
|
||||
return "%" + likeExpression.replace("%", "[%]") + "%";
|
||||
return "%" + likeExpression.replace("%", "\\%") + "%";
|
||||
}
|
||||
|
||||
public static String createLeftMatchLikeExpression(String likeExpression) {
|
||||
return likeExpression.replace("%", "[%]") + "%";
|
||||
return likeExpression.replace("%", "\\%") + "%";
|
||||
}
|
||||
|
||||
public static String createRightMatchLikeExpression(String likeExpression) {
|
||||
return "%" + likeExpression.replace("%", "[%]");
|
||||
return "%" + likeExpression.replace("%", "\\%");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -295,7 +295,6 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
myCaptureQueriesListener.logSelectQueries();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSearchWithContainsLowerCase() {
|
||||
myDaoConfig.setAllowContainsSearches(true);
|
||||
|
@ -333,6 +332,37 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchWithPercentSign() {
|
||||
myDaoConfig.setAllowContainsSearches(true);
|
||||
|
||||
Patient pt1 = new Patient();
|
||||
pt1.addName().setFamily("Smith%");
|
||||
String pt1id = myPatientDao.create(pt1).getId().toUnqualifiedVersionless().getValue();
|
||||
|
||||
Bundle output = myClient
|
||||
.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.contains().value("Smith%"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
List<String> ids = output.getEntry().stream().map(t -> t.getResource().getIdElement().toUnqualifiedVersionless().getValue()).collect(Collectors.toList());
|
||||
assertThat(ids, containsInAnyOrder(pt1id));
|
||||
|
||||
Patient pt2 = new Patient();
|
||||
pt2.addName().setFamily("Sm%ith");
|
||||
String pt2id = myPatientDao.create(pt2).getId().toUnqualifiedVersionless().getValue();
|
||||
|
||||
output = myClient
|
||||
.search()
|
||||
.forResource("Patient")
|
||||
.where(Patient.NAME.contains().value("Sm%ith"))
|
||||
.returnBundle(Bundle.class)
|
||||
.execute();
|
||||
ids = output.getEntry().stream().map(t -> t.getResource().getIdElement().toUnqualifiedVersionless().getValue()).collect(Collectors.toList());
|
||||
assertThat(ids, containsInAnyOrder(pt2id));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchWithDateInvalid() throws IOException {
|
||||
HttpGet get = new HttpGet(ourServerBase + "/Condition?onset-date=junk");
|
||||
|
|
Loading…
Reference in New Issue