Repository navigation
fix(#3823): funsub ${...} bodies treat # comments and heredocs as opaque spans - #3836
Merged
Merged
Conversation
…que spans
Root cause: three funsub/${...} extent scanners quote-tracked through
# comments and heredoc bodies, so an apostrophe in a comment (# don't)
opened a phantom single-quote that swallowed the rest of the input, and
a } line inside a heredoc body either closed the funsub early or was
swallowed with it. ${x:-$(...)} leaked its closing } into the default
word for the same reason one layer down (the ${...} body collector had
no $(...) unit arm).
GNU anchors (bash 5.3): parse.y:3631-3645 shell_getc (# at a token start
discards to EOL); parse.y:4451 parse_comsub (body parsed by the real
parser); parse.y:5506 funsub (parser.h:85 FUNSUB_CHAR); make_cmd.c:512
make_here_document (body read as raw lines); subst.c:1825
extract_dollar_brace_string.
- src/lexer/skip.rs: Lexer::skip_braced funsub branch gains a
token-boundary-gated # comment arm and a << heredoc arm.
- src/executor/command_substitution.rs: extract_funsub_body_tail gains
the same two arms (new push_funsub_heredoc helper).
- src/executor/command_subst_helpers.rs: collect_braced_parameter_body_into
skips $(...) as one unit via skip_parenthesized_unit_corrected.
- src/lexer/dolbrace.rs: skip_parenthesized gains a # comment arm
(comment-only; heredocs stay with the corrected scanner) + unit test.
- src/lexer/alias_stream.rs: skip_dollar_brace gains a funsub branch
delegating to skip_funsub_body.
- tests/issue3823_funsub_lexer_residual.rs: regression pins f1/h2/h3/d1.
Known limitation: f1/h2/h3 also need the mut walker's funsub collector
(expand_current_shell_braced_substitution, embedded_mutations.rs), which
is BLOCKED on in-flight #3817 (same file). Until that hunk lands, the
f1/h2/h3 pins are expected RED (literal-text values); d1 is green with
this change. See REPORT.md in the workdir.
Refs: #3823
Member
Author
|
【P1 车道复核】PR #3836 — 判词:SKIP / 半成品(按 PR 自述,3/4 钉按设计仍红;缺的 hunk 依赖 #3817,而 #3817 本轮判 FAIL)
红钉即阻断:合入会给 master 带 3 条红(该 stem 当前不在
未关闭 PR / 未关闭 #3823(保持 OPEN);本 PR 保持 draft。 |
…opaque spans (Refs #3823) Complete the two missing funsub arms so all four pins pass: - expand_current_shell_braced_substitution (embedded_mutations.rs): add the at_word_start token-boundary state, the parse.y:3631 shell_getc `#` comment arm, and the make_cmd.c:512 heredoc arm (reusing push_funsub_heredoc, `<<<` stays a herestring), mirroring extract_funsub_body_tail. - scan_braced_chars_from (dolbrace.rs): dispatch `${`+FUNSUB_CHAR to alias_stream::skip_funsub_body so the residual gates (param_residuals, unquoted_brace_group_depth, command_substitutions_balanced, continuation.rs callers) stop closing the span at a `}` inside a heredoc body or a `'` inside a comment. - db_scan_dolbrace_body (skip.rs): same FUNSUB_CHAR dispatch into a new db_scan_funsub_body carrying comment/heredoc/quote/comsub arms and the command-position `}` close, so unclosed_dollar_bracket_eof stops reporting a phantom `'` for f1/h2. - current_shell_command_substitution_span (parameter_core.rs): take the extent from extract_funsub_body itself instead of a parallel depth count, so the detector and the collectors share one scan; `prefix${| echo reply }suffix` now correctly has no span (GNU: unexpected EOF while looking for matching `}', rc 2). GNU anchors: parse.y:3631-3645 shell_getc, parse.y:4451 parse_comsub, parse.y:5506 FUNSUB_CHAR (parser.h:85), make_cmd.c:512 make_here_document, parse.y:5400-5416 funsub `}` close. Probed on GNU bash 5.3.20: all four pin shapes and the heredoc `}`-line variants match byte-for-byte.
Member
Author
|
【WIN-AGENT-AUDIT】 PR #3836 第2轮 — 建议:PASS(待队长 ready/合并裁决) 机制核查:
腿(逐项):
F 点:无 续作记录:
未跑/VOID 的腿:
|
caomengxuan666
marked this pull request as ready for review
November 17, 2026 11:35
This was referenced Nov 17, 2026
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.
Refs #3823
根因
真 lexer 层残差(#3813 的余项):三处 funsub/
${...}范围扫描器在#注释与 heredoc 体内继续做引号跟踪,于是注释里的撇号(# don't)打开一个幻影单引号,把剩余输入全部吞掉;heredoc 体内的}行要么提前关闭 funsub,要么被一并吞掉。${x:-$(...)}的}漏进值里是同一机制在下一层:walk 侧${...}体收集器没有$(...)单元臂,'吞掉闭合},}就成了默认值的一部分。GNU 锚点(bash 5.3)
shell_getc:#在 token 起始位置恒为注释,丢弃至行尾。parse_comsub:funsub/$(...)体由真实解析器解析,注释与 heredoc 是不透明 span。FUNSUB_CHAR)。make_here_document:heredoc 体按原始行读取。extract_dollar_brace_string:${...}内的$(...)span 交给 parse_comsub。GNU bash 5.3.20 实测:四形皆 rc=0 且值为预期(
v=[hi]/v=[it's here]/v=[}]/v=[hi])。改动
src/lexer/skip.rs:Lexer::skip_bracedfunsub 分支新增 token-boundary 门控的#注释臂与<<heredoc 臂(复用skip_heredoc_in_command_substitution)。src/executor/command_substitution.rs:不可变 walk 的extract_funsub_body_tail补同样的两臂(新增push_funsub_heredoc流式 helper:header + 体行原样复制、定界符 dequote、<<-去 tab、引号定界符、<<<herestring 不当 heredoc)。src/executor/command_subst_helpers.rs:collect_braced_parameter_body_into把$(...)作为一个单元整体跳过(经skip_parenthesized_unit_corrected)。src/lexer/dolbrace.rs:skip_parenthesized补#注释臂(仅注释;heredoc 仍归 corrected scanner)+ 单元测试comment_quote_inside_nested_comsub_does_not_swallow_closing_brace。src/lexer/alias_stream.rs:skip_dollar_brace补 funsub 分支,委托给skip_funsub_body(否则预扫描把 funsub 词吞到 EOF,闭合别名E永不展开)。tests/issue3823_funsub_lexer_residual.rs:回归钉四格(f1/h2/h3/d1,从 modernish builtin.t 007 解析死亡:别名 { f() { + $(…) 内奇数撇号注释致 rc=2 #3813 钉文件拆出,改名issue3823_*)。预期钉状态(重要:f1/h2/h3 暂红)
expand_current_shell_braced_substitution,src/executor/embedded_mutations.rs),其 funsub 收集器同样缺这两臂。该文件被在飞 PR test: add fail-first regression pins for literal control-byte constants (Refs #3816) #3817(字面控制字节常量损坏:32 个 CC 常量中 10 个被替换为元字符 #3816)占用,按同文件面护栏本 PR 未动它;在该 hunk 落地前,f1/h2/h3 钉会以字面值失败(rc=0,v为${...}原文)。队长决断后由后续车道在 test: add fail-first regression pins for literal control-byte constants (Refs #3816) #3817 合入后补该 hunk(设计已就绪:镜像skip_braced的两臂——at_word_start式 token-boundary 状态、#跳至\n、<<经 heredoc helper、term=true仅当paren_depth==0)。本 PR 删除了什么
无删除。仅新增:
push_funsub_heredochelper、钉文件、dolbrace 单元测试;其余皆为既有扫描器补臂。验证(欠账,见 REPORT)
src/lexer/+src/parser/与 base a0a6d78 等价)与 GNU 5.3.20 oracle 上已复现/对照;钉的 fail-first 证据见 modernish builtin.t 007 解析死亡:别名 { f() { + $(…) 内奇数撇号注释致 rc=2 #3813 REPORT §6(同四格在预扫描修复后仍红)。RUSTFLAGS="-D warnings"、rustfmt --check)、服务器 Linux 腿。VM→服务器出口代理中断、本地无 cargo/rustfmt 且 MemAvailable 低于 1.5G 构建门,故本轮未跑;路由恢复后补跑。UNVERIFIED-BY-CAPTAIN