fix(parse): 孤立 * 行不再 panic(exit 101 → 干净诊断)
qdagent 全仓 labels 扫描期间实测:任何 .mq.md 里有一行只含单个 `*`
(markdown 强调残留)时,`*…* = 返回` 分支同时满足 starts_with/ends_with('*'),
切片 &trimmed[1..0] 越界,整条 labels 扫描被一个文件打死(exit 101)。
修复:斜体返回分支要求 len >= 2,裸 `*` 落回 "unrecognized statement"
干净错误而非崩溃。
实测:
- tests/errors/lone-asterisk.mq.md → check 报 "unrecognized statement: *",
exit 1(不再 101)
- gold 回归 error_lone_asterisk_line 通过
- cargo test --release 全套件 0 failed
This commit is contained in:
1 parent
bf76e069ee
commit
bcfc763ba4
3 files changed
+27
-2
No files matched your search
+6
-2
@@ -444,8 +444,12 @@ impl<'a> Cursor<'a> {
|
||||
);
|
||||
}
|
||||
|
||||
// v0.3: *…* = return
|
||||
if trimmed.starts_with('*') && trimmed.ends_with('*') && !trimmed.starts_with("**") {
|
||||
// v0.3: *…* = return. A lone `*` (markdown emphasis leftover) must NOT
|
||||
// enter this branch: it both starts and ends with `*`, and the slice
|
||||
// below would panic (`[1..0]`). Require a real opener+closer pair; a
|
||||
// bare `*` falls through to the ordinary statement error / narration
|
||||
// handling instead of crashing the whole process.
|
||||
if trimmed.starts_with('*') && trimmed.ends_with('*') && trimmed.len() >= 2 && !trimmed.starts_with("**") {
|
||||
let inner = &trimmed[1..trimmed.len() - 1];
|
||||
return stmt_from_italic_return(inner, span);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
title: lone asterisk line must not panic
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
前面是一行只有单个星号的叙述残留。
|
||||
|
||||
*
|
||||
@@ -763,6 +763,18 @@ fn error_syntax_bad_line() {
|
||||
);
|
||||
}
|
||||
|
||||
/// 回归(qdagent labels 全仓扫描期间实测):孤立的 `*` 行曾令解析器 panic
|
||||
/// (`begin <= end (1 <= 0)`,exit 101,整条 labels 扫描被一个文件打死)。
|
||||
/// 修复后必须是干净的 `unrecognized statement` 诊断,而不是进程崩溃。
|
||||
#[test]
|
||||
fn error_lone_asterisk_line() {
|
||||
assert_err(
|
||||
"tests/errors/lone-asterisk.mq.md",
|
||||
"9:1",
|
||||
"unrecognized statement",
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn error_div_zero() {
|
||||
|
||||
Reference in new issue
Block a user