From 8d5524da75be1ab0a802a3835b8e3a951d6760a0 Mon Sep 17 00:00:00 2001 From: agarcia Date: Tue, 10 Mar 2020 14:19:40 +0100 Subject: [PATCH] Support for usernames with character + --- .../lib/resources/files/RemoteFile.java | 23 +-------- .../lib/resources/files/RemoteFileUtil.kt | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFileUtil.kt diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.java b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.java index e8892e6e..740641aa 100644 --- a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.java +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFile.java @@ -1,5 +1,5 @@ /* ownCloud Android Library is available under MIT license - * Copyright (C) 2019 ownCloud GmbH. + * Copyright (C) 2020 ownCloud GmbH. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,7 +24,6 @@ package com.owncloud.android.lib.resources.files; -import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; @@ -41,14 +40,11 @@ import at.bitfire.dav4android.property.owncloud.OCId; import at.bitfire.dav4android.property.owncloud.OCPermissions; import at.bitfire.dav4android.property.owncloud.OCPrivatelink; import at.bitfire.dav4android.property.owncloud.OCSize; -import okhttp3.HttpUrl; import java.io.Serializable; import java.math.BigDecimal; import java.util.List; -import static com.owncloud.android.lib.common.OwnCloudClient.WEBDAV_FILES_PATH_4_0; - /** * Contains the data of a Remote File from a WebDavEntry * @@ -115,7 +111,7 @@ public class RemoteFile implements Parcelable, Serializable { } public RemoteFile(final Response davResource, String userId) { - this(getRemotePathFromUrl(davResource.getHref(), userId)); + this(RemoteFileUtil.Companion.getRemotePathFromUrl(davResource.getHref(), userId)); final List properties = davResource.getProperties(); for (Property property : properties) { @@ -167,21 +163,6 @@ public class RemoteFile implements Parcelable, Serializable { readFromParcel(source); } - /** - * Retrieves a relative path from a remote file url - *

- * Example: url:port/remote.php/dav/files/username/Documents/text.txt => /Documents/text.txt - * - * @param url remote file url - * @param userId file owner - * @return remote relative path of the file - */ - private static String getRemotePathFromUrl(HttpUrl url, String userId) { - final String davFilesPath = WEBDAV_FILES_PATH_4_0 + userId; - final String absoluteDavPath = Uri.decode(url.encodedPath()); - final String pathToOc = absoluteDavPath.split(davFilesPath)[0]; - return absoluteDavPath.replace(pathToOc + davFilesPath, ""); - } /** * Getters and Setters diff --git a/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFileUtil.kt b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFileUtil.kt new file mode 100644 index 00000000..ace0675b --- /dev/null +++ b/owncloudComLibrary/src/main/java/com/owncloud/android/lib/resources/files/RemoteFileUtil.kt @@ -0,0 +1,49 @@ +/* ownCloud Android Library is available under MIT license + * Copyright (C) 2020 ownCloud GmbH. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ +package com.owncloud.android.lib.resources.files + +import android.net.Uri +import com.owncloud.android.lib.common.OwnCloudClient +import okhttp3.HttpUrl + +class RemoteFileUtil { + companion object { + /** + * Retrieves a relative path from a remote file url + * + * + * Example: url:port/remote.php/dav/files/username/Documents/text.txt => /Documents/text.txt + * + * @param url remote file url + * @param userId file owner + * @return remote relative path of the file + */ + fun getRemotePathFromUrl(url: HttpUrl, userId: String): String? { + val davFilesPath = OwnCloudClient.WEBDAV_FILES_PATH_4_0 + userId + val absoluteDavPath = Uri.decode(url.encodedPath()) + val pathToOc = absoluteDavPath.split(davFilesPath)[0] + return absoluteDavPath.replace(pathToOc + davFilesPath, "") + } + } +}