[Android] MlStorage: fix ban / unban when space in filename
Duncan McNamara
git at videolan.org
Wed Oct 5 07:46:11 UTC 2022
vlc-android | branch: 3.5.x | Duncan McNamara <dcn.mcnamara at gmail.com> | Fri Sep 30 17:15:22 2022 +0200| [3db6b9bb06e711fb32286df593de00b1262f07be] | committer: Nicolas Pomepuy
MlStorage: fix ban / unban when space in filename
The list of banned folders returned by the medialibrary returns an
encoded path, including spaces which aren't encoded by
VLCUtil.encodeVLCString. To properly compare strings in the ban unban
callback, it is necessary to manually encode the space.
(cherry picked from commit 9e6675b0c85391dea5cacc0de9289991c92a037f)
> https://code.videolan.org/videolan/vlc-android/commit/3db6b9bb06e711fb32286df593de00b1262f07be
---
.../src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt | 6 +++---
.../src/org/videolan/vlc/gui/helpers/MedialibraryUtils.kt | 7 ++++---
medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java | 4 ++--
medialibrary/src/org/videolan/medialibrary/Tools.java | 7 +++++++
4 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
index 9e1f30c50..20700f09a 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/StorageBrowserFragment.kt
@@ -40,8 +40,8 @@ import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.videolan.libvlc.util.AndroidUtil
-import org.videolan.libvlc.util.VLCUtil
import org.videolan.medialibrary.MLServiceLocator
+import org.videolan.medialibrary.Tools
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.medialibrary.interfaces.media.MediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
@@ -111,8 +111,8 @@ class StorageBrowserFragment : FileBrowserFragment(), BrowserContainer<MediaLibr
addBannedFoldersCallback { folder, _ ->
(adapter as StorageBrowserAdapter).bannedFolders = Medialibrary.getInstance().bannedFolders().toList()
adapter.dataset.forEachIndexed{ index, mediaLibraryItem ->
- if ("${VLCUtil.encodeVLCString((mediaLibraryItem as Storage).uri.toString())}/" == folder) adapter.notifyItemChanged(index)
- }
+ if ("${Tools.mlEncodeMrl(((mediaLibraryItem as Storage).uri.toString()))}/" == folder) adapter.notifyItemChanged(index)
+ }
}
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/MedialibraryUtils.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/MedialibraryUtils.kt
index 9d0874089..f7e797eb0 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/MedialibraryUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/MedialibraryUtils.kt
@@ -5,6 +5,7 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.core.net.toUri
+import org.videolan.medialibrary.Tools
import org.videolan.medialibrary.interfaces.Medialibrary
import org.videolan.resources.ACTION_DISCOVER
import org.videolan.resources.ACTION_DISCOVER_DEVICE
@@ -46,14 +47,14 @@ object MedialibraryUtils {
}
return isScanned
}
-
+
/**
* Return true if this uri/path is banned (because it is or a parent is)
* @param uri the uri to test
* return true is the uri is banned
*/
fun isBanned(uri: Uri, bannedFolders: List<String>) = isBanned(uri.toString(), bannedFolders)
- fun isBanned(path: String, bannedFolders: List<String>) = bannedFolders.any { path.encodeMrlWithTrailingSlash().startsWith("$it") }
+ fun isBanned(path: String, bannedFolders: List<String>) = bannedFolders.any { Tools.mlEncodeMrl(path).encodeMrlWithTrailingSlash().startsWith("$it") }
/**
* Return true if this uri/path is banned (but false if a parent is)
@@ -61,5 +62,5 @@ object MedialibraryUtils {
* return true is the uri is strictly banned
*/
fun isStrictlyBanned(uri: Uri, bannedFolders: List<String>) = isStrictlyBanned(uri.toString(), bannedFolders)
- fun isStrictlyBanned(path: String, bannedFolders: List<String>) = bannedFolders.any { path.encodeMrlWithTrailingSlash() == "$it" }
+ fun isStrictlyBanned(path: String, bannedFolders: List<String>) = bannedFolders.any { Tools.mlEncodeMrl(path).encodeMrlWithTrailingSlash() == "$it" }
}
diff --git a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
index 7df915f5d..e1b02b1fd 100644
--- a/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
+++ b/medialibrary/src/org/videolan/medialibrary/MedialibraryImpl.java
@@ -110,12 +110,12 @@ public class MedialibraryImpl extends Medialibrary {
public void banFolder(@NonNull String path) {
if (mIsInitiated && new File(path).exists())
- nativeBanFolder(Tools.encodeVLCMrl(path));
+ nativeBanFolder(Tools.mlEncodeMrl(path));
}
public void unbanFolder(@NonNull String path) {
if (mIsInitiated && new File(path).exists())
- nativeUnbanFolder(Tools.encodeVLCMrl(path));
+ nativeUnbanFolder(Tools.mlEncodeMrl(path));
}
public String[] bannedFolders() {
diff --git a/medialibrary/src/org/videolan/medialibrary/Tools.java b/medialibrary/src/org/videolan/medialibrary/Tools.java
index b0aa9290c..7c91be6c1 100644
--- a/medialibrary/src/org/videolan/medialibrary/Tools.java
+++ b/medialibrary/src/org/videolan/medialibrary/Tools.java
@@ -134,6 +134,13 @@ public class Tools {
return sb.toString();
}
+ public static String mlEncodeMrl(String mrl) {
+ if (mrl.startsWith("/")) mrl = "file://"+mrl;
+ mrl = mrl.replace(" ", "%20");
+ mrl = mrl.replace("+", "%2B");
+ return VLCUtil.encodeVLCString(mrl);
+ }
+
public static String encodeVLCMrl(String mrl) {
if (mrl.startsWith("/")) mrl = "file://"+mrl;
return VLCUtil.encodeVLCString(mrl);
More information about the Android
mailing list