Skip to content

fix(#505): multi-line [[ ]] with folded ((...)) continuations parse like GNU; readline surface residual (#431); #433 rc ledger pinned - #571

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/legacy-505-431-433
Oct 12, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/legacy-505-431-433

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

三张老票的遗留清偿

#505 — 函数体内跨行 [[ + || 起始续行被拒(生态重审计唯一活缺陷)

根因(vendored 源锚定):rubash 的 lexer 在命令位把平衡的 ((...)) 折叠成单个 Keyword token;cond 收集器把它当单个 WORD 操作数,于是续行换行在 binop 槽裸露 → unexpected token 'newline', conditional binary operator expected。

GNU 语义(third_party/bash/ 逐行锚定):

  • parse.y:3780 read_token:( 的算术命令特例门控在 (parser_state & (PST_CASEPAT|PST_CONDCMD)) == 0 —— [[ ]] 内 ( 一律按 cond 分组 token 投递,[[ ((x == 0)) ]] 是 group(group(binary))(parse.y:5094-5110 cond_term)。
  • 每个词项收尾都跑 (void)cond_skip_newlines()(parse.y:5108 组闭合、:5140 一元、:5243 二元 RHS)——闭合组之后的换行不可见;裸词的 binop 槽是裸 read_token(parse.y:5179),换行在那里照样报错(GNU 实测 [[ x + 换行 + ]] 同拒)。

修法:collect_conditional_args 把折叠 token 重切回 GNU 读者会产出的组 token 群(=~ RHS 例外——PST_REGEXP 下 RHS 是一个词,parse.y:5443)。

验收(WSL GNU bash 5.3.0 双向存证):

  • issue 最小复现 -n 通过、实跑输出 IN-FUNC-OK 与 GNU 一致(修前 rc=2 双拒)
  • 原资产 sheldritch/sheldritch core/args.sh(56394 B)rubash -n 通过(修前精确失败于行 1307)
  • 要素矩阵收敛:函数体 + if/while/f() ( + 跨行 + || ((...)) 续行为触发面;顶层同构本就通过
  • GNU 拒收形态不松动:[[ x+换行+]]、[[ (x) == x ]]、[[ ((x)) q ]] 等仍以 GNU 同文拒收

#431 残余(交接单 #479:inputrc 读取 / bind -v / inputrc 解析面)

  • bind -v/-V:48 变量 GNU 5.3 全表(顺序、默认值、set X V / X is set to `V' 两种格式,探针逐行对齐)。
  • set NAME VALUE:bind 参数与 inputrc 文件双通道进表;未知名 readline: NAME: unknown variable name、editing-mode 坏值 readline: editing-mode: could not set value to `bogus'(GNU 同文,rc 恒 0);布尔非 on 归 off、数字垃圾归 0(静默,GNU 探针);set editing-mode vi 联动 keymap vi-insert。
  • inputrc 解析面:$if term=/mode= 条件(大小写敏感;同文件 set editing-mode 武装后续 mode= 块)、$else/$endif 嵌套、$include(缺失静默)。
  • initialize_readline(bashline.c:451,bind.def:131 / y.tab.c:4024 触发):$INPUTRC → ~/.inputrc 每进程一次——-c 下首个 bind 即生效(GNU 同),rcfile 先于 inputrc。
  • 错误通道分流:positional 绑定解析失败走 readline: … 且不影响 rc(bind.def:304-333 忽略 rl_parse_and_bind 返回);-x 失败保持 bind: 通道 rc 1;非引号非 set positional 静默忽略(GNU bind 'ls -l' rc 0)。

reedline 上游清单(引擎侧已完成、需宿主编辑器接行为,已写入 bind_builtins.rs 模块文档):-p/-P/-l 全表(reedline 键表只覆盖 GNU 176 函数名的子集);超出宿主键解析器的多键序列;变量表在编辑器内的行为落点(今天宿主只消费 editing-mode/keymap,其余 46 项是数据面)。

#433 记账

残账口径「PC parse-error rc=2 vs GNU 0」在现行 master 已闭合(4b6234c5 及后续):五形态探针(EOF 即错/中段错/PC 正常/无 PC/末提示符错)GNU 与 rubash 全部 rc=0 一致。本次把账锁死:三条交互回归(EOF 终局 rc=0、中段错 rc=0、PC='exit 7' 仍以 7 胜出)并入 issue433 回归文件。

测试证据

  • 新增 tests/issue505_multiline_cond_folded_arith_regressions.rs:15/15(含 GNU 拒收控件)
  • 新增 tests/issue431_readline_surface_regressions.rs:18/18
  • 扩充 tests/issue433_prompt_command_exit_regressions.rs:9/9
  • 全量 cargo test --no-fail-fast:本分支失败集 53 名 vs fresh master(eb062957)失败集 53 名,逐名双向 diff 为空(双侧同集合:command_chaining 15、bashdb_compat 13、examples 10 等环境依赖项,双侧同源)
  • cargo fmt --check 干净

GNU 探针存证

全部 accept/reject 判定来自 WSL GNU bash 5.3.0(/usr/local/bin/bash,仓库基线)脚本文件探针:parse.y cond 语法 12 形、bind -v/-V 全表、set 校验 9 形、inputrc 条件/include 6 形、PC rc 5 形。

…ike GNU; readline surface residual (#431); #433 rc ledger pinned

#505: rubash's lexer folds a balanced ((...)) at command position into one
Keyword token; the cond collector modeled it as a single WORD operand, so
the continuation-line newline before ]] surfaced in the binop slot
('conditional binary operator expected') inside function bodies. GNU's
reader delivers ( as the grouping token inside [[ ]] - the arithmetic fold
is gated on (parser_state & (PST_CASEPAT|PST_CONDCMD)) == 0 (parse.y:3780) -
and every completed term ends with cond_skip_newlines (parse.y:5108 group
close, 5140 unary, 5243 binary rhs), hiding newlines after a CLOSED GROUP.
collect_conditional_args now re-splits the fold into the group token
population GNU produced (except after =~, whose RHS is one word under
PST_REGEXP, parse.y:5443). Acceptance: the wt92 minimal repro and
sheldritch/sheldritch core/args.sh both pass -n and run like GNU.

#431 residual (handover #479 rows inputrc/bind -v): bind -v/-V dump the
48-variable GNU 5.3 table; set NAME VALUE flows from bind arguments and
inputrc files (GNU diagnostics, boolean/number normalization, editing-mode
-> keymap coupling); inputrc parsing applies $if term=/mode= conditionals
(case-sensitive, in-file set arms later blocks), $else/$endif, $include;
initialize_readline reads $INPUTRC/~/.inputrc once per process on the
first bind (bind.def:131) or prompt (y.tab.c:4024); positional binding
failures moved to the readline: channel with no status effect
(bind.def:304-333 ignores rl_parse_and_bind's return) and non-quote non-set
arguments are silently ignored. reedline-upstream rows (-p/-P/-l full
tables, multi-key sequences, variable behavior in the editor) documented in
bind_builtins.rs.

#433 ledger: final-rc parity after a trailing PC parse error (GNU 0)
locked with three interactive regressions; current master already agrees.
…uote domain by construction (#571)

scripts/check-utf8-boundary-hygiene.sh (landed post-rebase) flagged
bind.rs:448 `delimiter: Some(d as char)`. The widened byte is the
isolate_sequence delimiter, matched only against b'"' (0x22) / b'''
(0x27) - ASCII by construction, never a UTF-8 continuation byte; the
value is echoed in diagnostics and compared for equality
(BindSpecError::delimiter). Tight allowlist entry beside the two
existing bind.rs rows.
@caomengxuan666
caomengxuan666 merged commit d116874 into master Oct 12, 2026
6 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/legacy-505-431-433 branch October 13, 2026 02:00
caomengxuan666 added a commit that referenced this pull request Oct 13, 2026
M0 design draft for rubash#497, written to be startable as-is:

- Scope pinned: one debuggee topology (script in the host process,
  pdb/debugpy model), DAP minimal surface over stdio (launch /
  same-process-spawn-only attach / setBreakpoints by file:line /
  stackTrace / scopes / variables / evaluate / pause-continue-step).
- Stop substrate anchored to the existing run_debug_trap seam family —
  all 11 dispatch points enumerated with file:line at 7f18b44
  (trap_exec.rs:716 funnel; ast_exec.rs:541; compound_exec.rs:334/982/
  1135/1170/1232/2305; function_calls.rs:531; loop_select.rs:117;
  pipeline_exec.rs:672; select_exec.rs:64) plus the function-return
  patch point (trap_exec.rs:781) for the extdebug force-return hole.
- Breakpoint injection: recommends executor PC hooks (the seam family is
  the PC, GNU DEBUG-trap distribution is the stop-site set, no second
  admission list per #117) with the parse-tree line walk
  (parser/nodes.rs:1252 CommandNode.line) used only for verified:false
  resolution at setBreakpoints time; reasons stated.
- Frame/scope/evaluate reuses landed structures: funcname_stack /
  bash_source_stack / bash_lineno_view (dynamic_arrays.rs:683/687/409),
  main-frame rule (#519, dynamic_arrays.rs:389-395), ERR entry-state
  parity pattern (#520), function_definition_locations
  (function_calls.rs:495-511); extdebug surface (#569 sites,
  trap_exec.rs:773-775) and #571 bind -v registry as the CLI's
  readline foundation.
- Non-goals, acceptance (golden DAP transcripts + bashdb oracle),
  scale estimate (~3,000-4,500 LOC, no new crates), M1 outlook, and
  three owner decision points (frontend order; --debug flag semantics;
  M0 stop-site granularity).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant