Fix an issue with spaces in user ids

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2019-05-02 10:57:49 +02:00 committed by Mario Đanić
parent 71de8a5245
commit db46330d6e

View file

@ -20,6 +20,7 @@
package com.nextcloud.talk.components.filebrowser.webdav;
import android.net.Uri;
import at.bitfire.dav4android.DavResource;
import at.bitfire.dav4android.Response;
import at.bitfire.dav4android.exception.DavException;
@ -34,14 +35,15 @@ import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
public class ReadFilesystemOperation {
private final OkHttpClient okHttpClient;
private final String url;
private final String basePath;
private final int depth;
private final int cutOff;
public ReadFilesystemOperation(OkHttpClient okHttpClient, UserEntity currentUser, String path, int depth) {
OkHttpClient.Builder okHttpClientBuilder = okHttpClient.newBuilder();
@ -49,7 +51,8 @@ public class ReadFilesystemOperation {
okHttpClientBuilder.followSslRedirects(false);
okHttpClientBuilder.authenticator(new RestModule.MagicAuthenticator(ApiUtils.getCredentials(currentUser.getUsername(), currentUser.getToken()), "Authorization"));
this.okHttpClient = okHttpClientBuilder.build();
basePath = currentUser.getBaseUrl() + DavUtils.DAV_PATH + currentUser.getUserId();
String basePath = currentUser.getBaseUrl() + DavUtils.DAV_PATH + currentUser.getUserId();
cutOff = (currentUser.getBaseUrl() + DavUtils.DAV_PATH + Uri.encode(currentUser.getUserId(), String.valueOf(StandardCharsets.UTF_8))).length();
this.url = basePath + path;
this.depth = depth;
}
@ -86,10 +89,10 @@ public class ReadFilesystemOperation {
}
remoteFiles.add(BrowserFile.getModelFromResponse(rootElement[0],
rootElement[0].getHref().toString().substring(basePath.length())));
rootElement[0].getHref().toString().substring(cutOff)));
for (Response memberElement : memberElements) {
remoteFiles.add(BrowserFile.getModelFromResponse(memberElement,
memberElement.getHref().toString().substring(basePath.length())));
memberElement.getHref().toString().substring(cutOff)));
}
davResponse.setData(remoteFiles);