Skip to content

Commit 4752808

Browse files
authored
Update FileStorageUtils.java
Fix crash when decoding filenames with invalid % characters Signed-off-by: chagaiB <[email protected]>
1 parent f2efe8b commit 4752808

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,24 @@ public final class FileStorageUtils {
7373
private FileStorageUtils() {
7474
// utility class -> private constructor
7575
}
76+
// Safely decodes URLs without crashing on '%' patterns
77+
private static String safeUrlDecode(String s){
78+
try{
79+
return java.net.URLDecoder.decode(s, StandardCharsets.UTF_8.name());
80+
}
81+
catch (IllegalArgumentException e){
82+
// If the text has invalid % sequences (like "65% on ..."), return as-is
83+
return s;
84+
}
85+
}
86+
7687

7788
public static boolean containsBidiControlCharacters(String filename) {
7889
if (filename == null) return false;
7990

8091
String decoded;
8192
try {
82-
decoded = URLDecoder.decode(filename, StandardCharsets.UTF_8.toString());
93+
decoded = safeUrlDecode(filename);
8394
} catch (UnsupportedEncodingException e) {
8495
return false;
8596
}

0 commit comments

Comments
 (0)