diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/interceptor/SearchPreferHandlingInterceptorJpaTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/interceptor/SearchPreferHandlingInterceptorJpaTest.java index 071641fe3a2..925783d07da 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/interceptor/SearchPreferHandlingInterceptorJpaTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/interceptor/SearchPreferHandlingInterceptorJpaTest.java @@ -122,5 +122,52 @@ public class SearchPreferHandlingInterceptorJpaTest extends BaseResourceProvider assertEquals(ourServerBase + "/Patient?_format=json&_pretty=true&identifier=BLAH", outcome.getLink(Constants.LINK_SELF).getUrl()); } + @Test + public void testSearchWithChain_Invalid() { + try { + myClient + .search() + .forResource(Patient.class) + .where(new StringClientParam("foo.bar").matches().value("bar")) + .withAdditionalHeader(Constants.HEADER_PREFER, Constants.HEADER_PREFER_HANDLING + "=" + Constants.HEADER_PREFER_HANDLING_STRICT) + .prettyPrint() + .returnBundle(Bundle.class) + .encodedJson() + .execute(); + fail(); + } catch (InvalidRequestException e) { + assertThat(e.getMessage(), containsString("Unknown search parameter \"foo\" for resource type \"Patient\". Valid search parameters for this search are: [_id, _language, active, address, address-city, address-country, address-postalcode, address-state, address-use, birthdate, death-date, deceased, email, family, gender, general-practitioner, given, identifier, language, link, name, organization, phone, phonetic, telecom]")); + } + + } + + @Test + public void testSearchWithChain_Valid() { + Bundle outcome = myClient + .search() + .forResource(Patient.class) + .where(new StringClientParam("organization.name").matches().value("bar")) + .withAdditionalHeader(Constants.HEADER_PREFER, Constants.HEADER_PREFER_HANDLING + "=" + Constants.HEADER_PREFER_HANDLING_STRICT) + .prettyPrint() + .returnBundle(Bundle.class) + .encodedJson() + .execute(); + assertEquals(0, outcome.getTotal()); + } + + + @Test + public void testSearchWithModifier_Valid() { + Bundle outcome = myClient + .search() + .forResource(Patient.class) + .where(new StringClientParam("name").matchesExactly().value("bar")) + .withAdditionalHeader(Constants.HEADER_PREFER, Constants.HEADER_PREFER_HANDLING + "=" + Constants.HEADER_PREFER_HANDLING_STRICT) + .prettyPrint() + .returnBundle(Bundle.class) + .encodedJson() + .execute(); + assertEquals(0, outcome.getTotal()); + } } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/SearchPreferHandlingInterceptor.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/SearchPreferHandlingInterceptor.java index d3192c91d8f..cee31ba18a5 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/SearchPreferHandlingInterceptor.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/interceptor/SearchPreferHandlingInterceptor.java @@ -117,6 +117,15 @@ public class SearchPreferHandlingInterceptor { continue; } + // Strip modifiers and chains + for (int i = 0; i < paramName.length(); i++) { + char nextChar = paramName.charAt(i); + if (nextChar == '.' || nextChar == ':') { + paramName = paramName.substring(0, i); + break; + } + } + RuntimeSearchParam activeSearchParam = searchParamRetriever.getActiveSearchParam(resourceName, paramName); if (activeSearchParam == null) {