Issue #5364 InvalidPathException: Illegal char <:> at index 5:

https://hos... at ca.uhn.fhir.util.UrlUtil.getAboveUriCandidates() on
Windows
This commit is contained in:
Bill Denton 2023-10-12 00:23:55 -07:00
parent c832cf0507
commit 07801e9ed7
1 changed files with 22 additions and 6 deletions

View File

@ -609,12 +609,16 @@ public class UrlUtil {
* Example input: http://[host]/[pathPart1]/[pathPart2]
* Example output: http://[host], http://[host]/[pathPart1], http://[host]/[pathPart1]/[pathPart2]
*
* Note that [pathPart2] also will contain any query string and/or fragment from the input
* Note also that all parts of url are as presented in the input without any %xx decoding
*
* @param theUri String URI parameter
* @return List of URI candidates
*/
public static List<String> getAboveUriCandidates(String theUri) {
URI uri = null;
try {
URI uri = new URI(theUri);
uri = new URI(theUri);
if (uri.getScheme() == null || uri.getHost() == null) {
throwInvalidRequestExceptionForNotValidUri(theUri, null);
}
@ -623,12 +627,24 @@ public class UrlUtil {
}
List<String> candidates = new ArrayList<>();
Path path = Paths.get(theUri);
candidates.add(path.toString().replace(":/", "://"));
while (path.getParent() != null && path.getParent().toString().contains("/")) {
candidates.add(path.getParent().toString().replace(":/", "://"));
path = path.getParent();
String path = uri.getScheme() + "://";
int stopLen = path.length();
path += uri.getRawAuthority() + uri.getRawPath();
if (uri.getRawQuery() != null) {
path += "?" + uri.getRawQuery();
}
if (uri.getRawFragment() != null) {
path += "#" + uri.getRawFragment();
}
candidates.add(path);
int ix = path.length();
while ((ix = path.substring(0, ix-1).lastIndexOf('/')) > stopLen) {
candidates.add(path.substring(0, ix));
}
return candidates;
}