Repository navigation
fix(executor): keep a $( body parse error fatal to the enclosing command (Refs #3756) - #3843
Merged
Merged
Conversation
…mmand (Refs #3756) GNU early.md anchor: parse.y:4451 parse_comsub hands the body to the grammar while the word is read; a body grammar failure is yyerror -> jump_to_top_level (DISCARD), so the enclosing input unit is abandoned whole and NOTHING in it executes. Three rubash defects kept that from holding after #3756 released truncated-case comsub units: 1. expand_command_substitution_with_context reset the body-error latch at every substitution entry, so a later substitution in the same word list cleared a fatal `$(` verdict and the command still ran (`echo $(case x in a|) $(echo ok)` printed `ok`, rc 0). 2. The abort in execute_command_with_procsub_scope keyed on last_command_substitution_status == Some(2); that slot is the documented left-to-right `$?` overlay and the next substitution overwrites it with its own child exit (0), masking the verdict. The latch alone now decides (every latch site also sets status 2). 3. The extractor's case machine never armed its pattern region for a plain `case WORD in` (word_boundary false after the subject word), so `$(case x in a|)` scanned as unclosed: the read-time body screen (rubash#2789) saw no node, and a skipped-branch body (`false && echo $(case x in a|)`) was silently ignored instead of killing the unit. GNU special_case_tokens rule 6 (parse.y:3369-3386) makes that `in` a reserved word regardless of boundary and parse.y:3379/3396 arms the region. Verified byte-identical to WSL GNU bash 5.3.20 on 15 shapes x {plain, quoted, assignment, pipeline, and-or-skip, adjacent-word, trailing command} at rc/stdout/stderr; issue3307/2784/2789/3229/435 and the case pins stay green.
…r (Refs #3756) The pattern region now arms at the `in` token (GNU special_case_tokens rule 6, parse.y:3369-3386), so the empty-case shape scans over its whole span instead of running off the end. Executed behavior is unchanged (`echo $(case x in esac)` and its sibling/assignment forms are byte-identical to GNU 5.3.20), so the old scan-level None expectation is replaced with the extracted span and the verified behaviors.
caomengxuan666
added a commit
that referenced
this pull request
Nov 18, 2026
…3701 (#3897) 1) Update keeps_comsub_case_subject empty-case expectation to Some("case $(ls) in esac") matching #3843 keeps_empty_case_esac_shape. 2) Restore exit status 2 for unmatched-delimiter EOF diagnostics in script_driver.rs (verified against GNU bash 5.3.20 in WSL: all word-internal pairs and -c/-n/file modes exit 2), keeping #3701 ANSI-C $'...' comsub walker fixes. 3) Restore status 2 assertions in consumer_tests.rs, issue1184_f6_backquote_eof_regressions.rs, and issue3605_eof_exit_status_word_pairs.rs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
根因
#3756(72e160b55)放开$(case x in a|)这类截断 case 单元后,comsub 体语法错误只在执行期判、且判据可被同一命令行里的后续替换覆盖,于是 GNU 的「读入期语法错误整段丢弃」退化成「打印错误后继续执行」:-c形态 GNU 127 / master 0。GNU 锚点
parse.y:4451 parse_comsub():comsub 体在读词时交给语法分析器;体语法错误 →yyerror→jump_to_top_level (DISCARD),整个读入单元被丢弃,里面任何命令都不执行。parse.y:3369-3386(special_case_tokens rule 6):case WORD in的in即使在非保留字边界上也是 IN;parse.y:3379/3396在此 arm pattern region。修法(三处,共 46 行)
expand_command_substitution_with_context的入口复位不再清除非 contained($(体,非 backtick/算术回退)的体错误闩锁 —— GNU 的体语法错误属于外层输入,同命令内的后续替换不得复活它;contained 体(subst.c string_locale -> parse_and_execute,子进程内解析)保持原逐点复位语义。execute_command_with_procsub_scope的中止判据改为只看闩锁。原先还要求last_command_substitution_status == Some(2),而该槽是文档化的$?左到右覆盖槽,下一个替换会写入自己子进程的 0,正好把致命结论抹掉(这就是ok被打印的直接原因)。所有闩锁点都同时置 2,判据不丢信息。dollar_command_substitution的 case 机器在case WORD in处未 arm pattern region(word_boundary在主语词之后为 false),$(case x in a|)被扫成未闭合 → 读入期 screen(rubash#2789)看不到截断体,跳过分支里的坏体(false && echo $(...))更是完全静默。按 rule 6 在in上 arm。验证(WSL GNU bash 5.3.20 逐字节比对 rc/stdout/stderr)
-c15 格:普通/引号/赋值/管道/and-or 跳过/相邻词/带后续命令 —— 除下列残差外全部一致(127、无输出、同诊断):ok)ok ok2)after)after, 无诊断)rc=2rc=2echo $(case a in a) echo hi;; esac)hi脚本文件形态 12 格同样逐字一致(
rc=2、无输出)。回归
tests/issue3756_comsub_parse_error_discard.rs(4 格):fail-first 已确认 —— 在 mastera593395f1上 3 格失败(sibling_substitution…、skipped_branch…、script_file…),本 PR 全绿。#3756自带tests/issue3307_repl_unclosed_case_comsub.rs4/4 绿(原修复不回退);issue27845/5、issue278911/11、issue322910/10、issue4359/9、case_command_head4/4、issue1091_1092_10933/3、issue1184_f6_backquote_tail8/8、issue20256/6、issue20265/5、issue14012/2、issue16187/7、issue16196/6、issue186_case_fallthrough1/1、d11_pipeline_squote_carrier6/6、comsub_nonascii_span10/10、issue14851/1、issue15897/7 全绿。a593395f1上逐字复现,非本 PR):issue1184_f6_backquote_eof2、issue160_unclosed_quote_command_string6、issue0069_…_comsub_capture1、issue19823;lib 1374 passed / 1 failed(api::consumer_tests::issue2084_…,master 上同样失败)。cargo fmt:仓级cargo fmt --check在本机报 os error 206(路径过长),改用rustfmt --check --edition 2021逐文件,通过。src/lexer/continuation.rs(captain-exclusive)。残差(本 PR 不动)
cat <<EOF\n$(case x in a|)\nEOF—— 两者 rc=0 且后续命令照跑,但诊断文本不同(GNUline 2: syntax error near unexpected token ')',rubashline 3: unexpected EOF while looking for matching ')');修前 master 即如此。$(case x in ()/(a|)/(|):GNU 127,rubash 2(修前 master 相同,属#3307的 gate 边界,见#3756正文)。$(case x in esac)在提取器里现在返回整段 span 而非 None(等价的扫描层变化,行为与 GNU 一致,单测期望已随之更新并注明)。Refs #3756 #3307 #3388