From 0245eb1e0ed94c1e6333fa5fe3af2caaea6ec58f Mon Sep 17 00:00:00 2001 From: Jemima Brewer Date: Thu, 23 Apr 2026 10:22:35 +0100 Subject: [PATCH 1/6] Fix getPathInPaths for whitespace and plain paths --- .../filemanager/filesystem/files/FileUtils.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java b/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java index 6b6a6bec65..5ea68b4b36 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java +++ b/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java @@ -590,23 +590,35 @@ public static String[] getFolderNamesInPath(String path) { * @return string array of incremental path segments */ public static String[] getPathsInPath(String path) { + + path = path.trim(); + if (path == "") { + return new String[0]; + } else if (path == "/") { + return new String[] {"/"}; + } if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } path = path.trim(); - ArrayList paths = new ArrayList<>(); @Nullable String urlPrefix = null; @Nullable Pair splitUri = splitUri(path); if (splitUri != null) { urlPrefix = splitUri.first; path = splitUri.second; + + if (path == null) { + return new String[] {urlPrefix}; + } } if (!path.startsWith("/")) { path = "/" + path; } + ArrayList paths = new ArrayList<>(); + while (path.length() > 0) { if (urlPrefix != null) { paths.add(urlPrefix + path); From b2c7bdb929180ae340a5c6f730724e699fd216ff Mon Sep 17 00:00:00 2001 From: Jemima Brewer Date: Thu, 23 Apr 2026 10:23:58 +0100 Subject: [PATCH 2/6] Add tests for getPathInPaths with whitespace and plain paths --- .../filesystem/files/FileUtilsTest.kt | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/app/src/test/java/com/amaze/filemanager/filesystem/files/FileUtilsTest.kt b/app/src/test/java/com/amaze/filemanager/filesystem/files/FileUtilsTest.kt index a75c54e152..00b22305d8 100644 --- a/app/src/test/java/com/amaze/filemanager/filesystem/files/FileUtilsTest.kt +++ b/app/src/test/java/com/amaze/filemanager/filesystem/files/FileUtilsTest.kt @@ -46,6 +46,55 @@ class FileUtilsTest { * * @see FileUtils.getPathsInPath */ + @Test + fun testGetPathsInPathForEmpty() { + getPathsInPath("").run { + assertEquals(0, size) + assertArrayEquals( + arrayOf(), + this, + ) + } + } + + @Test + fun testGetPathsInPathForWhitespace() { + getPathsInPath(" ").run { + assertEquals(0, size) + assertArrayEquals( + arrayOf(), + this, + ) + } + } + + @Test + fun testGetPathsInPathForSingleSlash() { + getPathsInPath("/").run { + assertEquals(1, size) + assertArrayEquals( + arrayOf( + "/", + ), + this, + ) + } + } + + @Test + fun testGetPathsInPathForSingleFolderWithSlashAtEnd() { + getPathsInPath("/dir/").run { + assertEquals(2, size) + assertArrayEquals( + arrayOf( + "/", + "/dir", + ), + this, + ) + } + } + @Test fun testGetPathsInPathForFolder() { getPathsInPath("/etc/default/grub/2/conf.d").run { From 7a4c5884b04bdf4143002936c558cb7e6dbb965c Mon Sep 17 00:00:00 2001 From: Jemima Brewer Date: Sun, 26 Apr 2026 13:44:02 +0100 Subject: [PATCH 3/6] Apply fixes for failed Codacy statis code analysis --- .../com/amaze/filemanager/filesystem/files/FileUtils.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java b/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java index 5ea68b4b36..008944836a 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java +++ b/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java @@ -589,12 +589,12 @@ public static String[] getFolderNamesInPath(String path) { * @param path * @return string array of incremental path segments */ - public static String[] getPathsInPath(String path) { - + public static String[] getPathsInPath(String pathParam) { + String path = pathParam; path = path.trim(); - if (path == "") { + if (path.equals("")) { return new String[0]; - } else if (path == "/") { + } else if (path.equals("/")) { return new String[] {"/"}; } if (path.endsWith("/")) { From 9c0cd8d1b06af66a77683e35965145f425a30149 Mon Sep 17 00:00:00 2001 From: Jemima Brewer Date: Sun, 26 Apr 2026 13:44:47 +0100 Subject: [PATCH 4/6] Add documentation for new tests --- .../filesystem/files/FileUtilsTest.kt | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/test/java/com/amaze/filemanager/filesystem/files/FileUtilsTest.kt b/app/src/test/java/com/amaze/filemanager/filesystem/files/FileUtilsTest.kt index 00b22305d8..26171046aa 100644 --- a/app/src/test/java/com/amaze/filemanager/filesystem/files/FileUtilsTest.kt +++ b/app/src/test/java/com/amaze/filemanager/filesystem/files/FileUtilsTest.kt @@ -42,7 +42,7 @@ import java.util.TimeZone @Suppress("TooManyFunctions", "StringLiteralDuplication") class FileUtilsTest { /** - * Test FileUtils.getPathsInPath() for directory + * Test FileUtils.getPathsInPath() with empty * * @see FileUtils.getPathsInPath */ @@ -57,6 +57,11 @@ class FileUtilsTest { } } + /** + * Test FileUtils.getPathsInPath() with just whitespace + * + * @see FileUtils.getPathsInPath + */ @Test fun testGetPathsInPathForWhitespace() { getPathsInPath(" ").run { @@ -68,6 +73,11 @@ class FileUtilsTest { } } + /** + * Test FileUtils.getPathsInPath() with single slash + * + * @see FileUtils.getPathsInPath + */ @Test fun testGetPathsInPathForSingleSlash() { getPathsInPath("/").run { @@ -81,6 +91,11 @@ class FileUtilsTest { } } + /** + * Test FileUtils.getPathsInPath() for folder with slash at end + * + * @see FileUtils.getPathsInPath + */ @Test fun testGetPathsInPathForSingleFolderWithSlashAtEnd() { getPathsInPath("/dir/").run { @@ -95,6 +110,11 @@ class FileUtilsTest { } } + /** + * Test FileUtils.getPathsInPath() for directory + * + * @see FileUtils.getPathsInPath + */ @Test fun testGetPathsInPathForFolder() { getPathsInPath("/etc/default/grub/2/conf.d").run { From 014716996f1412da8edaccdebacdd39f1275f071 Mon Sep 17 00:00:00 2001 From: Jemima Brewer Date: Sun, 26 Apr 2026 13:47:36 +0100 Subject: [PATCH 5/6] Change documentation for new parameter name --- .../java/com/amaze/filemanager/filesystem/files/FileUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java b/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java index 008944836a..f15b274922 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java +++ b/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java @@ -586,7 +586,7 @@ public static String[] getFolderNamesInPath(String path) { * ["smb://user;workgroup:passw0rd@12.3.4", "smb://user;workgroup:passw0rd@12.3.4/user", "smb://user;workgroup:passw0rd@12.3.4/user/Documents", "smb://user;workgroup:passw0rd@12.3.4/user/Documents/flare.doc"] * * - * @param path + * @param pathParam * @return string array of incremental path segments */ public static String[] getPathsInPath(String pathParam) { From 869af94c03ebb06e240e5268294e7ff1a6f4a4d7 Mon Sep 17 00:00:00 2001 From: Jemima Brewer Date: Sun, 26 Apr 2026 14:16:17 +0100 Subject: [PATCH 6/6] Add buildPaths function to reduce NPath complexity --- .../filesystem/files/FileUtils.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java b/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java index f15b274922..80c63b8496 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java +++ b/app/src/main/java/com/amaze/filemanager/filesystem/files/FileUtils.java @@ -592,9 +592,10 @@ public static String[] getFolderNamesInPath(String path) { public static String[] getPathsInPath(String pathParam) { String path = pathParam; path = path.trim(); - if (path.equals("")) { + if (path.isEmpty()) { return new String[0]; - } else if (path.equals("/")) { + } + if (path.equals("/")) { return new String[] {"/"}; } if (path.endsWith("/")) { @@ -617,8 +618,23 @@ public static String[] getPathsInPath(String pathParam) { path = "/" + path; } - ArrayList paths = new ArrayList<>(); + ArrayList paths = buildPaths(path, urlPrefix); + + paths.add(urlPrefix != null ? urlPrefix : "/"); + Collections.reverse(paths); + return paths.toArray(new String[0]); + } + + /** + * Splits a given path to URI prefix (if exists) and path. + * + * @param pathParam + * @return string array of incremental path segments + */ + public static ArrayList buildPaths(String pathParam, String urlPrefix) { + ArrayList paths = new ArrayList<>(); + String path = pathParam; while (path.length() > 0) { if (urlPrefix != null) { paths.add(urlPrefix + path); @@ -631,15 +647,7 @@ public static String[] getPathsInPath(String pathParam) { break; } } - - if (urlPrefix != null) { - paths.add(urlPrefix); - } else { - paths.add("/"); - } - Collections.reverse(paths); - - return paths.toArray(new String[0]); + return paths; } /**