Skip to content

Commit 85dae8f

Browse files
authored
Merge pull request #1908 from IBM/issue-1907
Signed-off-by: Lee Surprenant <[email protected]>
2 parents 8308c98 + 0d23644 commit 85dae8f

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

fhir-search/src/main/java/com/ibm/fhir/search/uri/UriBuilder.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ public UriBuilder requestUri(String requestUriString) {
7272
* @throws URISyntaxException
7373
*/
7474
public String toSearchSelfUri() throws URISyntaxException {
75-
URI requestUri = new URI(requestUriString);
75+
String hostAndPath = requestUriString.contains("?") ?
76+
requestUriString.substring(0, requestUriString.indexOf("?")) :
77+
requestUriString;
78+
URI requestUri = new URI(hostAndPath);
7679

7780
// Always include page size at the beginning, even if it wasn't in the request
7881
queryString.append(SearchConstants.COUNT);

fhir-search/src/test/java/com/ibm/fhir/search/uri/test/UriTest.java

+48-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
public class UriTest {
3333

3434
@Test
35-
public void testUriBadSecurity() throws URISyntaxException {
35+
public void testUriTrimmedUrl() throws URISyntaxException {
3636
String incoming =
3737
"https://localhost:9443/fhir-server/api/v4/_search?_count=10&_security=http://ibm.com/fhir/security&_fudge=tag&_page=1";
3838
String requestUriString = incoming.split("\\?")[0];
@@ -62,6 +62,37 @@ public void testUriBadSecurity() throws URISyntaxException {
6262
incoming);
6363
}
6464

65+
@Test
66+
public void testUriBadSecurity() throws URISyntaxException {
67+
String incoming =
68+
"https://localhost:9443/fhir-server/api/v4/_search?_count=10&_security=http://ibm.com/fhir/security&_fudge=tag&_page=1";
69+
String requestUriString = incoming;
70+
71+
QueryParameterValue value = new QueryParameterValue();
72+
value.setValueString("http://ibm.com/fhir/security");
73+
List<QueryParameterValue> values = Arrays.asList(value);
74+
QueryParameter parameter = new QueryParameter(Type.TOKEN, "_security", null, null, values);
75+
76+
List<QueryParameter> searchParameters = new ArrayList<>();
77+
78+
searchParameters.add(parameter);
79+
80+
QueryParameterValue value2 = new QueryParameterValue();
81+
value2.setValueString("tag");
82+
List<QueryParameterValue> values2 = Arrays.asList(value2);
83+
QueryParameter parameter2 = new QueryParameter(Type.TOKEN, "_fudge", null, null, values2);
84+
searchParameters.add(parameter2);
85+
86+
87+
FHIRSearchContext ctx = FHIRSearchContextFactory.createSearchContext();
88+
ctx.setPageNumber(1);
89+
ctx.setPageSize(10);
90+
ctx.setSearchParameters(searchParameters);
91+
92+
assertEquals(SearchUtil.buildSearchSelfUri(requestUriString, ctx),
93+
incoming);
94+
}
95+
6596
@Test
6697
public void testUriWithOnlyCompartmentInclusionSearchParmeter() throws URISyntaxException {
6798
String expectedUri = "https://localhost:9443/fhir-server/api/v4/Patient/1234/Observation?_count=10&_page=1";
@@ -79,4 +110,20 @@ public void testUriWithOnlyCompartmentInclusionSearchParmeter() throws URISyntax
79110
assertEquals(SearchUtil.buildSearchSelfUri(requestUriString, ctx), expectedUri);
80111
}
81112

113+
@Test
114+
public void testUriWithUnencodedPipe() throws URISyntaxException {
115+
String expectedUri = "https://test?_count=10&param=system%7Cvalue&_page=1";
116+
String requestUriString = "https://test?param=system|value";
117+
118+
FHIRSearchContext ctx = FHIRSearchContextFactory.createSearchContext();
119+
ctx.setPageNumber(1);
120+
ctx.setPageSize(10);
121+
QueryParameterValue paramVal = new QueryParameterValue();
122+
paramVal.setValueSystem("system");
123+
paramVal.setValueCode("value");
124+
QueryParameter queryParameter = new QueryParameter(Type.TOKEN, "param", null, null, Collections.singletonList(paramVal));
125+
ctx.setSearchParameters(Collections.singletonList(queryParameter));
126+
127+
assertEquals(SearchUtil.buildSearchSelfUri(requestUriString, ctx), expectedUri);
128+
}
82129
}

0 commit comments

Comments
 (0)