Skip to content

Commit

Permalink
Fix StringIndexOutOfBoundsException (#15319)
Browse files Browse the repository at this point in the history
Fixes #15318

Reverts #14402

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
  • Loading branch information
jlaur authored Jul 28, 2023
1 parent f6e750a commit 5732cca
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.commons.lang3.StringUtils;
import org.openhab.binding.digitalstrom.internal.lib.config.Config;
import org.openhab.binding.digitalstrom.internal.lib.manager.ConnectionManager;
import org.openhab.binding.digitalstrom.internal.lib.serverconnection.HttpTransport;
Expand Down Expand Up @@ -333,8 +334,7 @@ private String checkSessionToken(String request) {
}

private boolean checkNeededSessionToken(String request) {
String requestFirstPart = request.substring(0, request.indexOf("?"));
String functionName = requestFirstPart.substring(requestFirstPart.lastIndexOf("/") + 1);
String functionName = StringUtils.substringAfterLast(StringUtils.substringBefore(request, "?"), "/");
return !DsAPIImpl.METHODS_MUST_NOT_BE_LOGGED_IN.contains(functionName);
}

Expand All @@ -347,10 +347,8 @@ private String addSessionToken(String request, String sessionToken) {
correctedRequest = correctedRequest + "?" + ParameterKeys.TOKEN + "=" + sessionToken;
}
} else {
String strippedRequest = correctedRequest
.substring(correctedRequest.indexOf(ParameterKeys.TOKEN + "=") + ParameterKeys.TOKEN.length() + 1);
strippedRequest = strippedRequest.substring(0, strippedRequest.lastIndexOf("&"));
correctedRequest = correctedRequest.replaceFirst(strippedRequest, sessionToken);
correctedRequest = StringUtils.replaceOnce(correctedRequest, StringUtils.substringBefore(
StringUtils.substringAfter(correctedRequest, ParameterKeys.TOKEN + "="), "&"), sessionToken);
}
return correctedRequest;
}
Expand Down

0 comments on commit 5732cca

Please sign in to comment.