Skip to content

Commit

Permalink
Merge pull request #1880 from hapifhir/do-20250114-fix-param-encode
Browse files Browse the repository at this point in the history
Use URLEncoder.encode, deprecate worse named method
  • Loading branch information
grahamegrieve authored Jan 16, 2025
2 parents 5ae6e99 + 9bb7ac3 commit 8c03924
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public <T extends Resource> Parameters operateType(Class<T> resourceClass, Strin
if (!complex)
for (ParametersParameterComponent p : params.getParameter())
if (p.getValue() instanceof PrimitiveType)
ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ps += p.getName() + "=" + Utilities.encodeUriParam(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ResourceRequest<T> result;
if (complex)
result = utils.issuePostRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public static URI appendHttpParameters(URI basePath, Map<String, String> paramet
} else {
query = "";
}
query += httpParameterName + "=" + Utilities.encodeUri(parameters.get(httpParameterName));
query += httpParameterName + "=" + Utilities.encodeUriParam(parameters.get(httpParameterName));
}

return new URI(basePath.getScheme(), basePath.getUserInfo(), basePath.getHost(), basePath.getPort(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public <T extends Resource> Parameters operateType(Class<T> resourceClass, Strin
if (!complex)
for (ParametersParameterComponent p : params.getParameter())
if (p.getValue() instanceof PrimitiveType)
ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ps += p.getName() + "=" + Utilities.encodeUriParam(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ResourceRequest<T> result;
if (complex)
result = utils.issuePostRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public static URI appendHttpParameters(URI basePath, Map<String, String> paramet
} else {
query = "";
}
query += httpParameterName + "=" + Utilities.encodeUri(parameters.get(httpParameterName));
query += httpParameterName + "=" + Utilities.encodeUriParam(parameters.get(httpParameterName));
}

return new URI(basePath.getScheme(), basePath.getUserInfo(), basePath.getHost(), basePath.getPort(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public <T extends Resource> Parameters operateType(Class<T> resourceClass, Strin
if (!complex)
for (ParametersParameterComponent p : params.getParameter())
if (p.getValue() instanceof PrimitiveType)
ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ps += p.getName() + "=" + Utilities.encodeUriParam(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ResourceRequest<T> result;
URI url = resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps);
if (complex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public static URI appendHttpParameters(URI basePath, Map<String,String> paramete
} else {
query = "";
}
query += httpParameterName + "=" + Utilities.encodeUri(parameters.get(httpParameterName));
query += httpParameterName + "=" + Utilities.encodeUriParam(parameters.get(httpParameterName));
}

return new URI(basePath.getScheme(), basePath.getUserInfo(), basePath.getHost(),basePath.getPort(), basePath.getPath(), query, basePath.getFragment());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public <T extends Resource> Parameters operateType(Class<T> resourceClass, Strin
if (!complex)
for (ParametersParameterComponent p : params.getParameter())
if (p.getValue() instanceof PrimitiveType)
ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ps += p.getName() + "=" + Utilities.encodeUriParam(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ResourceRequest<T> result;
URI url = resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps);
if (complex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public static URI appendHttpParameters(URI basePath, Map<String, String> paramet
} else {
query = "";
}
query += httpParameterName + "=" + Utilities.encodeUri(parameters.get(httpParameterName));
query += httpParameterName + "=" + Utilities.encodeUriParam(parameters.get(httpParameterName));
}

return new URI(basePath.getScheme(), basePath.getUserInfo(), basePath.getHost(), basePath.getPort(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public <T extends Resource> Parameters operateType(Class<T> resourceClass, Strin
if (!complex)
for (ParametersParameterComponent p : params.getParameter())
if (p.getValue() instanceof PrimitiveType)
ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ps += p.getName() + "=" + Utilities.encodeUriParam(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ResourceRequest<T> result;
URI url = resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps);
if (complex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public static URI appendHttpParameters(URI basePath, Map<String, String> paramet
} else {
query = "";
}
query += httpParameterName + "=" + Utilities.encodeUri(parameters.get(httpParameterName));
query += httpParameterName + "=" + Utilities.encodeUriParam(parameters.get(httpParameterName));
}

return new URI(basePath.getScheme(), basePath.getUserInfo(), basePath.getHost(), basePath.getPort(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public <T extends Resource> Parameters operateType(Class<T> resourceClass, Strin
if (!complex)
for (ParametersParameterComponent p : params.getParameter())
if (p.getValue() instanceof PrimitiveType)
ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ps += p.getName() + "=" + Utilities.encodeUriParam(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ResourceRequest<T> result;
URI url = resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps);
if (complex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public static URI appendHttpParameters(URI basePath, Map<String,String> paramete
} else {
query = "";
}
query += httpParameterName + "=" + Utilities.encodeUri(parameters.get(httpParameterName));
query += httpParameterName + "=" + Utilities.encodeUriParam(parameters.get(httpParameterName));
}

return new URI(basePath.getScheme(), basePath.getUserInfo(), basePath.getHost(),basePath.getPort(), basePath.getPath(), query, basePath.getFragment());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.net.URI;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
Expand Down Expand Up @@ -926,11 +927,14 @@ public static String[] splitByCamelCase(String name) {
return parts.toArray(new String[]{});
}


public static String encodeUri(String v) {
return v.replace("%", "%25").replace(" ", "%20").replace("?", "%3F").replace("=", "%3D").replace("|", "%7C").replace("+", "%2B");
@Deprecated
public static String encodeUri(String string) {
return encodeUriParam(string);
}

public static String encodeUriParam(String param) {
return URLEncoder.encode(param, StandardCharsets.UTF_8);
}

public static String normalize(String s) {
if (noString(s))
Expand Down

0 comments on commit 8c03924

Please sign in to comment.