Skip to content
Snippets Groups Projects
Commit 9e6675b0 authored by Duncan McNamara's avatar Duncan McNamara Committed by Nicolas Pomepuy
Browse files

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.
parent 7d2bbb42
No related branches found
No related tags found
1 merge request!1565MlStorage: fix ban / unban when space in filename
......@@ -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)
}
}
}
......
......@@ -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" }
}
......@@ -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() {
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment