From 8386743454bb8f409f422891ccab5749dd1dcdd8 Mon Sep 17 00:00:00 2001 From: Selina Lin Date: Wed, 25 Oct 2023 21:48:00 +0200 Subject: [PATCH] Add check if `currentName` has an occurrence in `thisPath` --- .../java/com/amaze/filemanager/filesystem/HybridFile.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java b/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java index 649143bc6f..e351f42312 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java +++ b/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java @@ -555,7 +555,11 @@ public String getParent(Context context) { if (thisPath.isEmpty() || pathSegments.isEmpty()) return null; String currentName = pathSegments.get(pathSegments.size() - 1); - String parent = thisPath.substring(0, thisPath.lastIndexOf(currentName)); + int currentNameStartIndex = thisPath.lastIndexOf(currentName); + if (currentNameStartIndex < 0) { + return null; + } + String parent = thisPath.substring(0, currentNameStartIndex); if (ArraysKt.any(ANDROID_DATA_DIRS, dir -> parent.endsWith(dir + "/"))) { return FileProperties.unmapPathForApi30OrAbove(parent); } else {