Repository navigation
fix(lexer,executor): #880 close mark_quoted_ifs_from_raw bail blind spots - #898
arookieofc wants to merge 1 commit into
Conversation
… bail blind spots GNU parse.y:4451 parse_comsub re-parses the $(...) body with the real grammar, so a case clause owns its pattern `)` (parse.y:3465-3468 special_case_tokens); and subst.c:921-931 string_extract_double_quoted folds \" to a bare `"` while scanning the enclosing quotes (stripdq arm). The IFS-marking simulator replayed neither rule, and replayed no backtick line-continuation rule either, so any word pairing a quoted IFS char with one of these shapes desynced the simulated cook, hit the equality-guard bail, and split its quoted IFS: - dquote-wrapped backtick kept `\"` verbatim while the cook folds it (`a="`echo \"x\"`"` gave `"x"` for `x`); the chars-iterator backtick copier gains the dq flag and the dquote walker passes dq=true (outer backticks unchanged). The simulator's dquote backtick arm replays the same fold plus `\<newline>` elision. - backtick `\<newline>` / `\<CRLF>` elision was not replayed in the simulator's dquote backtick arm. - `$(...)` used a naive paren depth count that closed early on `$(case x in ...)` pattern parens; the tail was re-walked as outer text, so a `\`/`"`/`'` there desynced the cook and split quoted IFS (e.g. `"a b"$(case x in x) echo \$y;; esac)` gave `a` + `b$y`). Now case-aware, arm-for-arm with copy_dollar_paren_body_raw via the shared update_command_substitution_case_depth machine (parse.y:3710/ 3759, 3181/3183, 3630-3643; rubash#276/#284/#380/#513), with opaque quote/comment/nested-$() span skips (widened to pub(crate) with a lexer-level re-export). Mismatch still bails (safe direction); fixed shapes no longer bail. Evidence: target/probe/880r.sh + 880s.sh + 880t.sh + 880u.sh byte-match WSL GNU Bash 5.3.15; new tests/issue880_comsub_case_ifs_mark_regressions.rs 6/6; #868 7/7 + #876 7/7; regression 78/78; lib 706 + 1 pre-existing env-flaky windows_listing_cache (fails on clean master too).
|
欢迎!这是你的第一个 PR 🎉 请确认已跑过本地测试套件;CI 通过后维护者会 review。 |
Code Review (
|
独立复核(
|
| 侧 | 输出 |
|---|---|
| WSL GNU 5.3.0 | <a bxp> + <q> |
| master | <a> + <bxp> + <q>(错拆) |
| 本分支 | <a> + <bxp> + <q>(仍 bail 错拆) |
机理与第一轮评审一致:cook 侧两条路径——copy_backtick_body_cursor(dq=true)(quotes.rs:572/993)与本 PR 新增的 copy_backtick_body_preserving_syntax_dq——都把 \" 折成裸 "(0x22),但 command_prepare.rs:4645 的模拟器 '"' => 臂推的是 DATA_DQUOTE(markers.rs:102,\u{18})。\u{18} != '"' → simulated != cooked → 必然 bail。修法:改推 '"'。
现有 dquote_wrapped_backtick_escaped_quote_folds 测的是纯赋值词(走 remove_shell_quotes_outside_backticks,不进 mark_quoted_ifs_from_raw),所以没抓到。请补上面这个命令词形的回归测试(assert_script 直接可用)。
2. [Blocker] copy_comsub_body_verbatim_for_ifs_marking 反引号体 _ => 臂单步进,\` 提前闭合
复现:
printf '<%s>\n' "a b"$(echo `echo \`echo \\)\`` \$y)| 侧 | 输出 |
|---|---|
| WSL GNU 5.3.0 | <a b)> + <$y> |
| master | <a> + <b)> + <$y>(错拆) |
| 本分支 | <a> + <b)> + <$y>(仍 bail 错拆) |
机理:反引号体内 _ => 臂只推 \ 并 index += 1,被转义的 ` 下一轮被当闭合符 → 反引号提前闭合 → ) 提前闭合 $() → 尾部落入外层模拟 → bail。同函数的顶层 \\ 臂(成对推入并 +2)与 copy_dquote_span_verbatim_for_ifs_marking 的 \\ 臂都是成对处理,唯独这里不一致。修法:成对推入 \ + 被转义字符并 index += 2,对齐 copy_backtick_body_preserving_syntax(_dq)。
3. [Major/一致性问题] 外层未引用反引号臂仍缺 \<newline> / \<CRLF> 消除
command_prepare.rs:4608-4627(!in_single && !in_double)原样拷贝 \+换行。目前电池内 p01/p10 三方一致(GroupScanFeeder::push_main_line 已在输入层剥主行续行,raw 到不了带 \<LF> 的形态),属不可达的潜伏不一致。建议按第一轮评审方案:把两个 ch == ''分支合并为带dq 标志的一个,dq=false` 同样做消除,顺带消重。
4. 对抗矩阵新发现(存量、非本 PR 引入,属 Face 2 同族,请顺手覆盖或另开票跟踪)
同族形里还有两个形在 master 与本分支上同样错(不 bail,但 \" 不折叠、引号漏进输出):
printf '<%s>\n' $"a b`echo \"x\"`"$w # GNU: <a bxp> master/分支: <a b"x"p>
printf '<%s>\n' "a b`echo \"x\"`"$(echo p q) # GNU: <a bxp> master/分支: <a b"x"p>这两个形不走赋值路径也不 bail(simulated 恰与 cooked 相等),说明命令词 cook 路径上 \" 折叠并未真正生效。修 Blocker 1 时建议一并核对这条路径,避免修完模拟器后 cooked 仍然错。
另注记一条存量(不属于本票,仅供知悉):内嵌字面 CR 的 \+CR+LF 形(CRLF 脚本场景),master 与分支同为 <a bxyp>,GNU 5.3.0 为 <a bx·p>(CR 保留为数据)——输入层既有分歧,本 PR 新加的 \r\n 消除臂实际不可达。
5. 对拍与回归对照(无新红)
- 电池 33 LF 形:分支 30/33 逐字节对齐 GNU(唯二 bail 即上面 1/2,外加第 4 点 2 形中 p33 一处,p31 与 p03/p08 有重叠行)。CR 3 形 master==分支(存量)。相对 master:修复确认 Face 3 全 4 形 +
\$/\\("a becho $x \"$w)+ case 体内$'..'共 7 形,零新增分歧。 tests/issue880_comsub_case_ifs_mark_regressions6/6、issue8687/7、issue8767/7 绿;--test regression77/78,唯一失败upstream_suite_slice_snapshots在今晨 master 基线(base843_fails.txt)内,非本 PR 造成。- CI 7 项绿已确认;diff 5 文件(command_prepare/lexer mod/quotes/skip/新测试)全部对题,无夹带。
结论
修 Blocker 1(模拟器推裸 ")、Blocker 2(反引号体 _ 臂成对步进),补两条命令词形回归测试(含未引用展开兄弟),建议顺带处理第 3、4 点。推新 commit 后我再跑同一电池复核。
|
Rework PR opened: #936 — implements all findings from the review above (comment 6290178882), built directly on this branch's head
@a-rookie-of-C-language remains the author of record for the #880 fix; whichever of the two PRs merges first wins. |
Closes #880.
mark_quoted_ifs_from_rawBailund spots fixed via direction A (complete the walks); mismatch still bails (safe direction).GNU basis:
parse.y:4451parse_comsub +parse.y:3465-3468special_case_tokens;subst.c:921-931string_extract_double_quoted stripdq arm.\"folds to": the chars-iterator backtick copier gains adqflag and the dquote walker passesdq=true(outer backticks unchanged). The simulator's dquote backtick arm replays the same fold plus\<newline>elision.\<newline>/\<CRLF>elision completed in the simulator.$(...)is now case-aware, arm-for-arm withcopy_dollar_paren_body_raw, reusing the sharedupdate_command_substitution_case_depthmachine (parse.y:3710/3759, 3181/3183, 3630-3643); quote/comment/nested-$() spans are skipped opaquely (function widened topub(crate)with a lexer-level re-export).Evidence:
target/probe/880r.sh+880s.sh+880t.sh+880u.shbyte-match WSL GNU Bash 5.3.15; newtests/issue880_comsub_case_ifs_mark_regressions.rs6/6; #868 7/7 + #876 7/7; regression 78/78; lib 706 pass + 1 pre-existing env-flakywindows_listing_cache(fails on clean master too).