Skip to content

Commit d121b2a

Browse files
committed
🐛修复文件列表中文件名超过50个字符页面崩溃的bug
1 parent ff26a5a commit d121b2a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

android_debug_lib/src/main/java/com/itlgl/android/debuglib/DebugServer.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,18 @@ private Response fileListResponse(IHTTPSession session, File directory) throws E
281281
} catch (Exception e) {
282282
e.printStackTrace();
283283
}
284+
285+
// 有些文件名字会超过50个字符,导致FILE_ITEM_SPACE.substring超过50报错,格式化一下,大于45就把中间替换为...
286+
String childFileNameFormat = childFile.getName();
287+
if(childFileNameFormat.length() > 45) {
288+
childFileNameFormat = childFileNameFormat.substring(0, 20) + "..." + childFileNameFormat.substring(childFileNameFormat.length() - 20);
289+
}
284290
String item = fileListItemTemp
285291
.replace("${href}", childFile.getName() + (childFile.isDirectory() ? "/" : ""))
286-
.replace("${title}", childFile.getName())
287-
.replace("${text}", childFile.getName())
292+
.replace("${title}", childFileNameFormat)
293+
.replace("${text}", childFileNameFormat)
288294
.replace("${date}", fileDate)
289-
.replace("${space}", FILE_ITEM_SPACE.substring(childFile.getName().length()));
295+
.replace("${space}", FILE_ITEM_SPACE.substring(childFileNameFormat.length()));
290296
if(childFile.isFile() && childFile.canRead()) {
291297
item = item
292298
.replace("${style3}", "")

0 commit comments

Comments
 (0)