Repository navigation
test: add fail-first regression pins for literal control-byte constants (Refs #3816) - #3817
Conversation
A bare CR byte before LF is consumed as a CRLF line ending by the script reader before the lexer sees it (Windows leg: unquoted CR value comes back empty, escaped CR joins the next line) -- a line-ending face separate from #3816. 0x0d stays pinned by the quoted shapes.
…uote entry (Refs #3816) A literal C0 byte inside a quoted or unquoted word is user data, but it is byte-identical to one of the C0 transport carriers (markers.rs), so a bare copy let downstream decoders claim it as protocol: the assignment boundary dropped CTLESC pairs and IFS_GLUE, the walker tail restored DATA_* carriers to the characters they denote, and decode_to_visible_text decoded the rest. 10 of the 32 modernish CC constants were damaged this way (CC11 empty, CC14 as backslash, CC16 as \\' , CC17 as quote, CC18 as dquote, CC1A as backtick, CC1F as dollar, CC13/CC1C/CC1D empty). Tag each literal carrier byte at the dequote entry as a raw-byte marker pair (E000 + E001+byte) -- the same contract the ANSI-C decoder already applies to its decoded bytes (push_ansi_c_byte), whose output boundary restores the pair to the literal byte. The $'\\xXX' form was already 32/32 correct precisely because it tagged; literal source bytes now get the same treatment. Sites (all dequote entry; verbatim-copy helpers for re-parse are untouched -- they pass through this same entry and get tagged exactly once there): - lexer/ansi.rs: push_tagged_source_char / push_tagged_source_span (new shared helpers next to is_assignment_carrier_byte; span form bulk-copies when no carrier byte is present) - lexer/classification.rs: protect_fully_single_quoted_assignment - lexer/quotes.rs: remove_shell_quotes_inner_cursor (single-quote span, generic span, backslash-escaped char), remove_double_quoted_into_cursor (span), remove_double_quoted_into (iterator, per-char), remove_shell_quotes_outside_backticks (single-quote, backslash, unquoted arms) GNU anchors: parse.y:5694-5706 got_character/got_escaped_character (GNU inserts CTLESC before a CTLESC/CTLNUL byte arriving as data); subst.c:4807 dequote_string (removes only CTLESC bytes); subst.c:11882 case '\\'' (single-quoted span -> add_quoted_string as literal data).
out is &mut String in remove_double_quoted_into_cursor / remove_double_quoted_into, so the tagged-push call sites need &mut *out, not &mut out (E0596).
) remove_shell_quotes_inner_cursor's trigger-free fast path returned the raw word unchanged -- its admission ('no trigger byte') is not 'provably trivial' (#117): a word with no quote/escape trigger can still hold a literal control byte colliding with a transport carrier (V=<0x11>), which then rode bare into transport and was claimed as protocol downstream. A carrier byte now disqualifies the fast path exactly like a trigger byte; the walk tags it in its bulk span. This is the second leak behind the unquoted-assignment failure: the sq/dq/esc/sq-word shapes were fixed by the dequote-entry tagging (282489a) but unquoted assignment still failed the same 10 bytes. Adds an unquoted plain-word pin (same function, non-assignment position) alongside the assignment one.
Collapse the three over-wrapped forms rustfmt --edition 2021 --check flags in the dequote-entry tagging code (ansi.rs push_tagged_source_char / push_tagged_source_span, quotes.rs remove_shell_quotes_outside_backticks guard). No behavior change.
…ing (Refs #3816) niubash#200 owns ESC (0x1b): word-initial ESC is tagged once by tag_word_initial_raw_esc, mid-word ESC stays a bare byte. The #3816 dequote-entry tagging used is_assignment_carrier_byte (which covers 0x14..=0x1f, i.e. 0x1b), so it double-tagged the mid-word ESC and stripped the bare byte, breaking the two niubash#200 lib guards. 0x1b is not one of #3816's ten damaged constants, so excluding it does not affect the nine pins. is_assignment_carrier_byte itself is unchanged (ANSI-C decoder and printf/mapfile/read paths keep it).
…tick re-parse (Refs #3816) prepare_unquoted_heredoc_expansion turns \`/$ into DATA_BACKTICK/ DATA_DOLLAR so the walker scan does not read them as syntax. The whole-word backtick entry restores those carriers before the re-parse (decode_backtick_substitution_source); the embedded mut-walker backtick arm dispatched straight to the parser, so a bare DATA_BACKTICK rode into the re-parse, where the #3816 dequote tagging tagged it as a literal source byte and the argv-materialization restore (bare carriers only) missed it -- a literal backtick leaked as raw 0x1a. Apply the same carrier restores here; the walker scan already consumed backslash escapes, so no decode_old_style_backtick_source re-pass.
|
【WIN-AGENT-AUDIT】 机制核查:
腿:
F 点:
续作记录:无(判词 FAIL,未动分支;F1 修法已在 F1 下注明,待队长裁定是否续作) 未跑/VOID 的腿:
|
…ntrol-char-constants
|
【o1 收网判词:FAIL(unix 面真回归,未合并)】head
Windows(本机)腿:
WSL Linux 原生构建(
失败形态是语义性的、非超时: CI 归因(run 43971070773,census 与 master 同日同基底 run 43935071198 对比;后者 head 即本 PR 的 merge-base
结论:pin 与 Windows 面可以合,但产品修法在 unix 打穿了 respawn/async body 文本路径(可能方向:把 tagging 限定到真正需要保护的 dequote 出口,或把 respawn body 文本在传子进程前统一 restore)。建议作者按 unix 原生腿返工后再 ready;崩在这批 unix-gated 钉上不能 merge。伞 #3605 与 issue #3816 均保持 OPEN。 |
…' bytes literal (Refs #3816) Two regressions the #3816 dequote-entry tagging exposed on the unix census: 1. Respawn transport carried engine carriers into a re-lexed child. `bash_command_source_text` prints `redirect.target` — the COOKED word — so `>> "$V"` shipped `$V` + PARAM_NAME_END_MARKER (0x13). The child's dequote entry then tagged that protocol byte as literal data (#3816) and the redirect opened `/tmp/x\023`; every `( ... ) &` with a quoted variable redirect lost its output (issue2058/2202/2332/2388/ 3054/1820/1862/1649). GNU never re-lexes (fork children carry the AST), so the renderer must emit SOURCE-level text: new `markers::decode_transport_word_text` (the `heredoc_delimiter_text` chain, rubash#1151) is now shared by `redirect_target_source_text` (both redirect printers) and the here-document delimiter. 2. A compound array element `([0]=$'\\[a\\]')` leaked a literal 0x11. The preserve-quotes ANSI-C arm wraps the decoded bytes in the synthetic single-quoted span GNU's `sh_single_quote` produces (parse.y:5564-5571), so the bytes are already quoted data — the CTLESC glob protection that `escape_decoded_ansi_c_quotes` adds is only meaningful in an unquoted region. Inside the span the carrier is data, so the escape pair survived to argv (`array_compound_quote_regressions`). New `escape_decoded_ansi_c_quotes_unprotected` is used only by that arm. Marker-lint: allowlist the two bare-carrier restore sites in the embedded backtick re-parse (same "engine text, bare carrier is always protocol" invariant as the 20+ neighbours) and retire the redirections.rs replace entry folded into the shared helper. Verified (Windows + WSL Linux native): census stems of the audit list 9/10 green (issue1585 heredoc-in-comsub EOF warning still open), `array_compound_quote_regressions` 17/17, `issue3816_literal_control_bytes` 9/9, lib 1374 passed / 1 failed (known issue2084 env), marker-lint OK, `-D warnings` clean, rustfmt clean.
|
【o1 收网】第2轮 — 判词 PENDING(F1 已修,F2 10 格 → 剩 1 格):新 commit head 6c9bd96(父 F1(marker-lint 2 违规)— 已修
F2(census 10 格)— 9/10 已绿,剩 1 格WSL Linux 原生构建逐 stem 复跑(
根因(已定位,两个机制缺陷)
剩余 1 格的形态
腿(本轮实跑)
未跑/VOID:CI 逐格、WSL 全量 lib(磁盘曾到 43G 暂停构建,已恢复)、issue1585 的紫格修复。判 PENDING 而非 PASS:census 仍有 1 甲确定性红,合入会带一棵红进 master。 |
|
【P1 车道复核】PR #3817 第2轮 — 判词:FAIL(1 个 PR 引入的语义回归,跨 Windows/Linux 复现;前一轮 10 个 census 红 stem 中 9 个已由新 head 修好)
1) 上一轮 census 10 个红 stem 归因(同机同环境,Linux WSL,base=origin/master 独立 worktree)方法:
上一轮 respawn 族根因已由 2) 未修回归(阻断项):双引号 comsub 内 escaped-delimiter heredoc用例就是既有 stem echo "$(
cat <<\)
hi
))"
即结果里多出一个 3) 根因判断(GNU C 锚点)GNU: 本 head 的具体缺陷: 也就是说 #3816 的不变量「dequote 入口的 carrier 字节是用户数据」对通用 dequote 路径不成立:只有能证明是源字节的位置(例如 4) 变绿需要什么
未合并:head 仍带 1 条跨平台语义回归,合入即给 master 带红。 |
|
【P1 车道复核 · 补充】#3817 唯一残留的精确根因(已实验定位,供后续修法参考) 承接 2026-11-17 上一条评论(10 stem 归因表 + 唯一残留 精确机制GNU make_cmd.c:602-611 的「
#3816 的 dequote 入口 tagging 在 0x1c 上失配:
即:IFS_GLUE 在 dequote 入口既有字面源数据身份(本例赋值里用户写的真实 0x1c,必须保留),也有词法期簿记身份(mod.rs:1499 的拼接,必须被消费/删除),两者字节相同,dequote 这一层无法凭字节判定。 已验证的排除项
正确修法的方向(需要协议级改动)二选一,两者都属于 carrier/协议面,需按仓库规则跑完整 ledger(83 suite 切片 + 10 stem 台账):
本轮未选任一(会动 carrier 协议且无法在本地跑完整 ledger),故不合。上一轮的关键实测与 10 stem 归因表见本 PR 上一条评论( PR 保持 OPEN + draft,未 ready、未合入;issue #3816 保持 OPEN。 |
…(Refs #3816) The quote-removal command-substitution copiers closed a substitution at the first unescaped close-paren, ignoring here-documents gathered inside the body. GNU parse_comsub (parse.y:4451) gathers pending here-documents, so a close-paren on a delimiter-prefixed line is consumed by the gather, not read as the substitution closer (make_cmd.c:602-627). For a double-quoted substitution whose heredoc delimiter is a paren, the early close ejected the IFS_GLUE bookkeeping byte into the surrounding quote span, where the literal-carrier tagging encoded it as a raw-byte pair. The heredoc plan then lost its closed-by-paren evidence: the warning vanished and a paren-plus-0x1c leaked into the output. Mirror the span extractor: both body copiers (cursor and char forms) now consume here-document bodies via the same skip_heredoc_in_command_substitution the extractor uses, and copy arithmetic spans verbatim so a shift operator inside $((...)) is never misread as a here-document start (rubash#2930's guard).
|
【WIN-AGENT-REWORK】PR #3817 第3轮 — 建议:PASS(本地全腿绿;Unix-only census 腿待 Linux CI 复核) 根因与修法(回应上一轮精确根因评论)上一轮把残留归因为「IFS_GLUE 在 dequote 入口字节同形、无法判定身份」,给出两个协议级方向(源层前移 tagging / 专属 PUA 标记)。本轮实测发现更深一层的机制错误,修法不需要动 carrier 协议:
F 点回应
腿(逐项数字)
续作记录
未跑/VOID 的腿
|
…que spans (#3836) * fix(#3823): funsub ${...} bodies treat # comments and heredocs as opaque 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 * fix(executor): funsub ${...} bodies treat # comments and heredocs as 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. --------- Co-authored-by: 曹梦轩 <[email protected]>
根因(已验证)
字面 C0 字节在引号词内以裸字节进入 transport text,与 C0 载体标记同字节(markers.rs:CTLESC 0x11、PARAM_NAME_END_MARKER 0x13、DATA_BACKSLASH 0x14、PROTECTED_ESCAPED_SQUOTE 0x16、DATA_SQUOTE 0x17、DATA_DQUOTE 0x18、DATA_BACKTICK 0x1a、IFS_GLUE 0x1c、STORAGE_WORD_PREFIX 0x1d、DATA_DOLLAR 0x1f),被下游解码器当协议认领:赋值边界丢 CTLESC 对与 IFS_GLUE、walker 尾链把 DATA_* 还原为所指字符、decode_to_visible_text 解码其余。
$'\xXX'不受影响,因 decode_ansi_c_quoted + push_ansi_c_byte(lexer/ansi.rs)已在入口把解码出的载体字节编为 raw-byte 标记对(E000+E001+byte);单/双引号与非引号去引号路径没有这一步。modernish 32 个 CC 常量中 10 个因此损坏(CC11/CC13/CC14/CC16/CC17/CC18/CC1A/CC1C/CC1D/CC1F),其余 22 个与 GNU 一致;$'\xXX'形式 32/32 正确。修法引入的两处真回归(均已修掉,见下):
is_assignment_carrier_byte(含 0x1b),与 niubash#200 的词首-ESC 归属(tag_word_initial_raw_esc,词首打标记、词中保持裸字节)冲突,致 2 格 lib 红。prepare_unquoted_heredoc_expansion把\`` 转为 DATA_BACKTICK 供 walker 扫描;mut walker 反引号臂直接重解析,未走 whole-word 路径的decode_backtick_substitution_source` restore;重解析时单引号 span 含该载体字节,tagging 将其打成 [E000, E001+0x1a],argv 物化 restore 只认裸载体而漏过,echo 输出 raw 0x1a。GNU 锚点:parse.y:5694-5706 got_character/got_escaped_character(数据侧 CTLESC/CTLNUL 前插 CTLESC);subst.c:4807 dequote_string(只去 CTLESC);subst.c:11882 case
'\''(单引号 span 按字面数据处理);parse.y:4451 parse_comsub;subst.c:7143 command_substitute;parse.y:3877 parse_matched_pair(P_BACKQUOTE 下反斜杠只在$/反引号/\前特殊)。修法
src/lexer/ansi.rs(push_tagged_source_char/push_tagged_source_span)、src/lexer/classification.rs(protect_fully_single_quoted_assignment)、src/lexer/quotes.rs(remove_shell_quotes_inner_cursor单引号 span/通用 span/反斜杠转义、remove_double_quoted_into_cursorspan、remove_double_quoted_into逐字符、remove_shell_quotes_outside_backticks三臂、fast-path disqualifier);fast path 不得原样返回含载体字节的词。is_literal_source_carrier_byte(is_assignment_carrier_byte集排除 0x1b),5 处调用点改用它;is_assignment_carrier_byte本身不动(ANSI-C 解码器等仍用它)。decode_backtick_substitution_source相同的 restore(DATA_BACKTICK→反引号、CTLESC→删、DATA_DOLLAR→$、PROTECTED_BACKSLASH→\);walker 已消费\转义,故不重跑decode_old_style_backtick_source。回归钉
tests/issue3816_literal_control_bytes.rs(9 格,fail-first):单/双引号赋值 32 字节全留、非引号赋值、非引号词(含probe_unq_wordfast-path 钉)、反斜杠转义赋值、单引号词 32 字节全留、ANSI-C 赋值对照、单引号元字符守卫、32 常量拼接。基底 2/8,修后 9/9。验证(X299,Windows MSVC)
issue2084),与基底一致;heredoc CLI 单测 PASS;fmt 与RUSTFLAGS="-D warnings"check 全过;三项 hygiene 全过。24 61 20 60 20 5c 2a 0a,与测试期望一致。issue_753::case_9、upstream_suite_slice_snapshotsbraces snapshot),修后仍会红。详见 REPORT.md §6。本 PR 删除了什么
无功能删除。本 PR 只改 4 个源码文件(
src/lexer/ansi.rs、src/lexer/classification.rs、src/lexer/quotes.rs、src/executor/embedded_mutations.rs,均为修法与注释)并新增 1 个测试文件(tests/issue3816_literal_control_bytes.rs,9 格钉);efe7f47d仅做 rustfmt 折叠,无行为变化。未删任何公开 API、测试或行为;未碰src/lexer/continuation.rs;未改docs/api-ledger.md。UNVERIFIED-BY-CAPTAIN