Skip to content

Commit 20772a9

Browse files
committed
Handle new webdav path on redirects
Previously redirects with new webdav paths resulted in an IndexOutOfBoundsException as String.substring() was called with a -1 index. Signed-off-by: Luca Weiss <[email protected]>
1 parent 6ee3c38 commit 20772a9

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/java/com/nextcloud/common/NextcloudClient.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ class NextcloudClient(var baseUri: Uri,
133133
}
134134

135135
if (destination != null) {
136-
val suffixIndex = location.lastIndexOf(AccountUtils.WEBDAV_PATH_4_0)
136+
var suffixIndex = location.lastIndexOf(AccountUtils.WEBDAV_PATH_4_0)
137+
if (suffixIndex == -1) {
138+
suffixIndex = location.lastIndexOf(AccountUtils.WEBDAV_PATH_9_0)
139+
}
140+
check (suffixIndex != -1) { "Failed to find webdav substring in $location" }
137141
val redirectionBase = location.substring(0, suffixIndex)
138142
val destinationStr = destination
139143
val destinationPath = destinationStr.substring(baseUri.toString().length)

src/main/java/com/owncloud/android/lib/common/OwnCloudClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,12 @@ public RedirectionPath followRedirection(HttpMethod method) throws IOException {
269269
}
270270
if (destination != null) {
271271
int suffixIndex = locationStr.lastIndexOf(AccountUtils.WEBDAV_PATH_4_0);
272+
if (suffixIndex == -1) {
273+
suffixIndex = locationStr.lastIndexOf(AccountUtils.WEBDAV_PATH_9_0);
274+
}
275+
if (suffixIndex == -1) {
276+
throw new IllegalStateException("Failed to find webdav substring in " + locationStr);
277+
}
272278
String redirectionBase = locationStr.substring(0, suffixIndex);
273279

274280
String destinationStr = destination.getValue();

0 commit comments

Comments
 (0)