|
|
|
|
@ -309,6 +309,22 @@ public class MathQuestionGenerator {
|
|
|
|
|
* @return 切换是否成功
|
|
|
|
|
*/
|
|
|
|
|
private static boolean handleSwitchCommand(String command) {
|
|
|
|
|
// 【人工修复】修复字符串越界风险,添加长度检查
|
|
|
|
|
// 修改前:command.substring(3) 可能抛出StringIndexOutOfBoundsException
|
|
|
|
|
// 修改后:先检查命令长度,确保安全访问
|
|
|
|
|
if (command.length() < 3) {
|
|
|
|
|
System.out.println();
|
|
|
|
|
System.out.println("✗ 请输入小学、初中和高中三个选项中的一个");
|
|
|
|
|
System.out.println("按回车键继续...");
|
|
|
|
|
System.out.flush();
|
|
|
|
|
try {
|
|
|
|
|
@SuppressWarnings("unused")
|
|
|
|
|
int readResult = System.in.read();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
// 忽略读取错误
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
String targetGrade = command.substring(3).trim();
|
|
|
|
|
|
|
|
|
|
if (targetGrade.equals("小学") || targetGrade.equals("初中") || targetGrade.equals("高中")) {
|
|
|
|
|
@ -517,8 +533,14 @@ public class MathQuestionGenerator {
|
|
|
|
|
String line;
|
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
|
|
|
if (line.matches("\\d+\\.\\s+.+")) {
|
|
|
|
|
String question = line.substring(line.indexOf(".") + 1).trim();
|
|
|
|
|
historyQuestions.add(question);
|
|
|
|
|
// 【人工修复】修复字符串越界风险,添加安全检查
|
|
|
|
|
// 修改前:line.indexOf(".") 可能返回-1,导致substring(-1+1)问题
|
|
|
|
|
// 修改后:先检查indexOf结果,确保安全访问
|
|
|
|
|
int dotIndex = line.indexOf(".");
|
|
|
|
|
if (dotIndex != -1 && dotIndex + 1 < line.length()) {
|
|
|
|
|
String question = line.substring(dotIndex + 1).trim();
|
|
|
|
|
historyQuestions.add(question);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|