okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

StringIndexOutOfBoundsException on JavaNetCookieJar.java:103 - when the value contains only one double quote

Open usenbekov opened this issue 3 years ago • 3 comments

okhttp_3.12.x JavaNetCookieJar.java (https://github.com/square/okhttp/blob/okhttp_3.12.x/okhttp-urlconnection/src/main/java/okhttp3/JavaNetCookieJar.java) Line: 103

if (value.startsWith("\"") && value.endsWith("\"")) {
  value = value.substring(1, value.length() - 1);
}

Fails when the value contains only one double quote ("), because the length of the value=1, but it tries to substring with the startIndex=1

usenbekov avatar Oct 29 '21 10:10 usenbekov

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.String.substring(String.java:2064)
    at okhttp3.JavaNetCookieJar.decodeHeaderAsJavaNetCookies(JavaNetCookieJar.java:103)
    at okhttp3.JavaNetCookieJar.loadForRequest(JavaNetCookieJar.java:74)

usenbekov avatar Oct 29 '21 10:10 usenbekov

Unfortunately a number of tests on 3.12.x break now in the face of backports of features to JDK8. So it may not be a quick release.

yschimke avatar Oct 29 '21 13:10 yschimke

Looking forward for the fix to be released, do I understand correctly that all of the versions are still affected by this issue?

viljark avatar Mar 01 '22 09:03 viljark

No planned release of 3.12.x

yschimke avatar May 20 '23 20:05 yschimke