15m12 成书死循环根治: secondTail头部误用→secondHead(治457/467行while startsWith+secondTail头部判断尾部操作不一致, 头部有\n永不收敛致服务器卡死)
Auto Release / build (push) Successful in 4m23s
Auto Release / build (push) Successful in 4m23s
This commit is contained in:
@@ -454,7 +454,7 @@ public class CustomScreenManager implements Listener {
|
||||
String secondHalf = candidate.substring(cut);
|
||||
// 去掉末尾空白(但不影响中间内容)
|
||||
while (firstHalf.endsWith("\n") || firstHalf.endsWith(" ")) firstHalf = firstHalf.substring(0, firstHalf.length() - 1);
|
||||
while (secondHalf.startsWith("\n") || secondHalf.startsWith(" ")) secondHalf = secondTail(secondHalf);
|
||||
while (secondHalf.startsWith("\n") || secondHalf.startsWith(" ")) secondHalf = secondHead(secondHalf);
|
||||
pages.add(firstHalf);
|
||||
page = new StringBuilder(secondHalf);
|
||||
|
||||
@@ -464,7 +464,7 @@ public class CustomScreenManager implements Listener {
|
||||
String chunk = page.substring(0, nextCut);
|
||||
String remain = page.substring(nextCut);
|
||||
while (chunk.endsWith("\n") || chunk.endsWith(" ")) chunk = chunk.substring(0, chunk.length() - 1);
|
||||
while (remain.startsWith("\n") || remain.startsWith(" ")) remain = secondTail(remain);
|
||||
while (remain.startsWith("\n") || remain.startsWith(" ")) remain = secondHead(remain);
|
||||
pages.add(chunk);
|
||||
page = new StringBuilder(remain);
|
||||
}
|
||||
@@ -509,6 +509,18 @@ public class CustomScreenManager implements Listener {
|
||||
return s.substring(0, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 15m12 去头部空白(与 secondTail 对称)。
|
||||
* ★ 15m11 死循环根治:旧代码 while(xxx.startsWith("\n")) xxx = secondTail(xxx) 头部判断+尾部操作,
|
||||
* 当 xxx 头部有 \n 但尾部无空白时 secondTail 返回不变 → 死循环 → 服务器卡死崩溃。
|
||||
* 改 secondHead 去头部空白,while 条件与操作一致, 每轮削掉头部一个空白必收敛。
|
||||
*/
|
||||
private static String secondHead(String s) {
|
||||
int start = 0;
|
||||
while (start < s.length() && (s.charAt(start) == '\n' || s.charAt(start) == ' ')) start++;
|
||||
return s.substring(start);
|
||||
}
|
||||
|
||||
/**
|
||||
* 去 markdown 标记:# 标题、**加粗**、__下划线__、*斜体*、`代码`、> 引用、```代码块```。
|
||||
* 只保留文字,避免书页里出现一堆符号。
|
||||
|
||||
Reference in New Issue
Block a user