Skip to content

Commit 7c75c50

Browse files
authored
Fix crash when decoding filenames with invalid % characters
This commit adds a safeUrlDecode() helper that prevents IllegalArgumentException when filenames contain invalid % patterns (like "65% on Sonic Wave"). Instead of crashing, the filename is returned as-is and the app continues normally. Signed-off-by: chagaiB <[email protected]>
1 parent 4752808 commit 7c75c50

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

app/src/main/java/com/owncloud/android/utils/FileStorageUtils.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,23 @@ private FileStorageUtils() {
7474
// utility class -> private constructor
7575
}
7676
// Safely decodes URLs without crashing on '%' patterns
77-
private static String safeUrlDecode(String s){
77+
private static String safeUrlDecode(String filename){
7878
try{
79-
return java.net.URLDecoder.decode(s, StandardCharsets.UTF_8.name());
79+
return java.net.URLDecoder.decode(filename, StandardCharsets.UTF_8.name());
8080
}
81-
catch (IllegalArgumentException e){
81+
catch (IllegalArgumentException ignored){
8282
// If the text has invalid % sequences (like "65% on ..."), return as-is
83-
return s;
83+
return filename;
8484
}
8585
}
8686

8787

8888
public static boolean containsBidiControlCharacters(String filename) {
8989
if (filename == null) return false;
9090

91-
String decoded;
92-
try {
93-
decoded = safeUrlDecode(filename);
94-
} catch (UnsupportedEncodingException e) {
95-
return false;
96-
}
97-
91+
String decoded;
92+
decoded = safeUrlDecode(filename);
93+
9894
int[] bidiControlCharacters = {
9995
0x202A, 0x202B, 0x202C, 0x202D, 0x202E,
10096
0x200E, 0x200F, 0x2066, 0x2067, 0x2068,

0 commit comments

Comments
 (0)