Fix StringIndexOutOfBoundsException (#15319)

Fixes #15318

Reverts #14402

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2023-07-28 10:00:48 +02:00 committed by GitHub
parent f6e750a5ff
commit 5732cca7bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -43,6 +43,7 @@ import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager; 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.config.Config;
import org.openhab.binding.digitalstrom.internal.lib.manager.ConnectionManager; import org.openhab.binding.digitalstrom.internal.lib.manager.ConnectionManager;
import org.openhab.binding.digitalstrom.internal.lib.serverconnection.HttpTransport; import org.openhab.binding.digitalstrom.internal.lib.serverconnection.HttpTransport;
@ -333,8 +334,7 @@ public class HttpTransportImpl implements HttpTransport {
} }
private boolean checkNeededSessionToken(String request) { private boolean checkNeededSessionToken(String request) {
String requestFirstPart = request.substring(0, request.indexOf("?")); String functionName = StringUtils.substringAfterLast(StringUtils.substringBefore(request, "?"), "/");
String functionName = requestFirstPart.substring(requestFirstPart.lastIndexOf("/") + 1);
return !DsAPIImpl.METHODS_MUST_NOT_BE_LOGGED_IN.contains(functionName); return !DsAPIImpl.METHODS_MUST_NOT_BE_LOGGED_IN.contains(functionName);
} }
@ -347,10 +347,8 @@ public class HttpTransportImpl implements HttpTransport {
correctedRequest = correctedRequest + "?" + ParameterKeys.TOKEN + "=" + sessionToken; correctedRequest = correctedRequest + "?" + ParameterKeys.TOKEN + "=" + sessionToken;
} }
} else { } else {
String strippedRequest = correctedRequest correctedRequest = StringUtils.replaceOnce(correctedRequest, StringUtils.substringBefore(
.substring(correctedRequest.indexOf(ParameterKeys.TOKEN + "=") + ParameterKeys.TOKEN.length() + 1); StringUtils.substringAfter(correctedRequest, ParameterKeys.TOKEN + "="), "&"), sessionToken);
strippedRequest = strippedRequest.substring(0, strippedRequest.lastIndexOf("&"));
correctedRequest = correctedRequest.replaceFirst(strippedRequest, sessionToken);
} }
return correctedRequest; return correctedRequest;
} }