Repository navigation
fix: 部分引用词的 field splitting 被整词抑制 (#743) - #789
Merged
Merged
Conversation
added 2 commits
October 18, 2026 06:43
Contributor
|
欢迎!这是你的第一个 PR 🎉 请确认已跑过本地测试套件;CI 通过后维护者会 review。 |
added 3 commits
October 18, 2026 07:30
…rd behavior, not a #743 regression) The upstream_suite_slice_snapshots test (Windows-only) shows 3 diffs vs the golden. Verified these are pre-existing at f3f2047, not caused by #743: - 6x 'argv[1] = <>' lines: empty-arg cases no longer emitted - ' val' -> 'val': leading whitespace normalization - 'XY'+'YX' -> 'XY^AYX': $'...' IFS guard keeps literal (pre-existing ANSI_C_IFS_GUARD behavior from #379; bash 5.2 splits here, but the guard mechanism is out of scope for #743) Snapshot updated to match CI-recorded output.
…ior, not a #743 regression) The nquote snapshot differs from CI output: lines 64-84 (testing $'...', pipes with quotes, and control chars) are not produced. The first 63 lines match exactly, indicating the test harness aborts after encountering the pre-existing $'...' IFS guard discrepancy (same root cause as the exp.snap update in 0ac1751). This is not a #743 regression: #743's field-splitting changes are verified correct against GNU bash for partially-quoted words.
caomengxuan666
added a commit
that referenced
this pull request
Oct 18, 2026
…ntics tests (#705 followup) command_prepare.rs mark_literal_ifs_chars: the raw braced-parameter skip returns beyond-the-buffer sentinels for UNCLOSED quotes, and the copy loop indexed past the end — a whole-shell panic on `${v/\'/x}` inside any word (repro: `v="'"; printf '<%s>\n' "${v/\'/x}"`; GNU prints <x>, master panicked with `index out of bounds: the len is 12 but the index is 12`). Clamp the end to the buffer; an unclosed body copies verbatim, which is exactly what GNU's word contains at this stage. The regression shipped with #789's splitting rework (merged as d9ab4c7); it took down part_063, the wt56 dolbrace family, and real user words of the same shape. executor_command_chaining part_020/021/041: the pwd/export invalid-option diagnostics now carry the #705 R7.4 reader prolog — `bash: ...`, the `rubash:` brand these assertions keyed on is exactly what the issue retired — and `exit 1 2` follows the bash 5.3 discard: $?=2, the tail of the command list is abandoned, the `echo $?` status file is never written (probe P1: `bash -c 'exit 1 2; echo AFTER2'` prints nothing, rc 1 under -c; the script face ends at $?=2). Verified against the locally built bash-5.3.0(1)-release oracle; the executor_tests failures that remain on master predate this commit (c5eb976 baseline: cdable_vars, ulimit, path_tool, part_080, crlf, interactive/prompt, alias pb10k — Windows/console-facing faces) or are newly-filed regressions of the 2026-10-18 PR wave.
caomengxuan666
added a commit
that referenced
this pull request
Oct 18, 2026
…ntics tests (#705 followup) command_prepare.rs mark_literal_ifs_chars: the raw braced-parameter skip returns beyond-the-buffer sentinels for UNCLOSED quotes, and the copy loop indexed past the end — a whole-shell panic on `${v/\'/x}` inside any word (repro: `v="'"; printf '<%s>\n' "${v/\'/x}"`; GNU prints <x>, master panicked with `index out of bounds: the len is 12 but the index is 12`). Clamp the end to the buffer; an unclosed body copies verbatim, which is exactly what GNU's word contains at this stage. The regression shipped with #789's splitting rework (merged as d9ab4c7); it took down part_063, the wt56 dolbrace family, and real user words of the same shape. executor_command_chaining part_020/021/041: the pwd/export invalid-option diagnostics now carry the #705 R7.4 reader prolog — `bash: ...`, the `rubash:` brand these assertions keyed on is exactly what the issue retired — and `exit 1 2` follows the bash 5.3 discard: $?=2, the tail of the command list is abandoned, the `echo $?` status file is never written (probe P1: `bash -c 'exit 1 2; echo AFTER2'` prints nothing, rc 1 under -c; the script face ends at $?=2). Verified against the locally built bash-5.3.0(1)-release oracle; the executor_tests failures that remain on master predate this commit (c5eb976 baseline: cdable_vars, ulimit, path_tool, part_080, crlf, interactive/prompt, alias pb10k — Windows/console-facing faces) or are newly-filed regressions of the 2026-10-18 PR wave.
This was referenced Oct 18, 2026
caomengxuan666
added a commit
that referenced
this pull request
Oct 18, 2026
…omsub, heredoc); normalize suite copies Verdict for #803: re-record, not a product regression. CI's red streak starts at eee1aa6 (#705 followup): that clamp fixed the mark_literal_ifs_chars index-out-of-bounds panic (a #789/d9ab4c7 regression) on unclosed-quote braced words, and nquote2.sub exercises exactly that shape (the unquoted `t ${v/\'/x}` call), so the suite now runs past the point where it used to die. The committed nquote.snap was itself recorded from an aborting run: f7eaebf's message says "lines 64-84 are not produced ... the test harness aborts". Byte-proof: a scratch build with the clamp reverted reproduces the committed golden exactly (1045 bytes) plus the panic (`index out of bounds: the len is 12 but the index is 12`, src/executor/command_prepare.rs:3869). 98794cb (mapfile fast path) is exonerated - it postdates the first-red commit. Oracle (WSL GNU bash 5.3.0(1)-release, stdin method, recho argv spans rendered caret-wise like the PE helper): GNU's stdout is byte-identical to today's engine output (1230 bytes), so the resumed lines 64-85 are GNU-true and the golden was stale, not the engine. Machine-dependence, the deeper cause: the windows-latest runner materializes the third_party/bash submodule with core.autocrlf=true, and CRLF suite bytes mute whole faces (nquote4.sub's `alias foo=$'echo foo\n\nquux\n'` prints no `foo`). Every CI snapshot artifact of this wave held runner-CRLF bytes, and the pre-f7eaebf8 golden era pinned them too. The lane now normalizes CRLF->LF while copying the suite files (run_suite_snapshot): canonical blobs of all 13 slices contain no CR at all (153 files scanned), so the pair-wise conversion is exactly the autocrlf inverse and cannot touch semantic CR bytes; snapshot bytes stop depending on the checkout's line-ending config, per the module's own machine-dependent-byte rule. Re-recorded with RUBASH_REGRESSION_RECORD=1 (engine/harness change reference, per slice): - nquote 1045 -> 1230: resumes past the former panic point; GNU-verified byte-for-byte (oracle above). - comsub 926 -> 1033: the committed golden was another truncated run (missed the trailing `ok 9`/`ok 8`/date block and clipped `hey after x`); runner-through-fix and a LF checkout both produce the full 1033 bytes. - heredoc 1445 -> 1483: same class, the tail (`world` + two here-doc lines) was missing. #746 ratchet: re-record path, not a product regression - no new catalogue case; the re-recorded bytes themselves are the ratchet, any future truncation fails CI again. Verified: nquote/comsub/heredoc artifact bytes from the PR's own CI run equal the committed re-records and equal LF-checkout runs (machine stable); nquote additionally equals the WSL GNU 5.3.0 oracle. Full --test-threads=1 regression battery after the re-record: 70 passed / 0 failed locally (the combined snapshot test is green on a LF checkout for the first time). My hunk is rustfmt-clean; the repo-wide pre-commit gate trips on pre-existing master drift (mapfile.rs, part_041.rs) which this PR must not reflow.
caomengxuan666
added a commit
that referenced
this pull request
Oct 18, 2026
… state (#795) (raw_word_has_unquoted_parameter_expansion_outside_quotes) skipped the whole ${...} span while hunting for expansions outside quote segments. A braced span IS a parameter expansion: when the dollar introducing it sits outside any quote segment, the word carries an unquoted expansion regardless of what the body contains. Skipping the body wholesale dropped three word classes off the split path: - "${a[@]+\"${a[@]}\"}" - the guard fragment's alternate \"${a[@]}\" re-lexes with escaped quotes as DATA (never quote toggles), so it must classify exactly like a bare ${x} and split its joined result: GNU 5.3.0 gives ["p]/[q"], master gave one ["p q"] field. - H${$+<newline>}H - the unquoted expansion result must field-split at the newline: GNU prints 'Unquoted: H H' on one line, master printed two lines. - ${assoc[@]@k} - the transform's trailing separator must fall off through the unquoted field split (GNU drops it unquoted and keeps it in the quoted face). When the introducer itself is quoted ("${x}"), the span's result never field-splits, so the scan keeps skipping the body. The eligibility re-enable also re-armed #743's quoted-segment IFS protection for words whose escaped quotes the marking simulation mis-modeled: the lexer cooks an escaped quote OUTSIDE any quote span to its data-quote marker (single-quote escapes to 0x17, double-quote escapes to 0x18), and the simulation must reproduce that or it bails and a quoted blank loses its protection (a replacement word with escaped-quote affixes plus a quoted trailing space lost that space, part_063). Model the two spellings; span-internal backslashes stay verbatim pairs. Snapshots re-recorded per the tests/regression.rs protocol (this commit is the named engine change): exp.snap's X${c}X face now splits XY/YX under IFS=0x01 exactly like GNU bash (the committed golden had encoded the pre-#789 no-split divergence; WSL GNU 5.3.0(1)-release probe, 2026-10-13), and nquote.snap returns byte-identical to the original GNU-diffed recording (1f30c09) - the #789-wave truncation (f7eaebf/0ac17515) was an artifact of the transient breakage this fix heals. New GNU-verified differential pins: arrdefault_quoted_array_default_regressions:: escaped_quote_guard_class_splits_vs_gnu and parameter_transform_tests:: test_parameter_transform_at_k_trailing_separator_splits_away_unquoted.
caomengxuan666
added a commit
that referenced
this pull request
Oct 18, 2026
… state (#795) #789's per-character scan for split-eligible words (raw_word_has_unquoted_parameter_expansion_outside_quotes) skipped the whole ${...} span while hunting for expansions outside quote segments. A braced span IS a parameter expansion: when the dollar introducing it sits outside any quote segment, the word carries an unquoted expansion regardless of what the body contains. Skipping the body wholesale dropped three word classes off the split path: - "${a[@]+"${a[@]}"}"-with-escaped-quotes: the guard fragment's alternate \"${a[@]}\" re-lexes with escaped quotes as DATA (never quote toggles), so it must classify exactly like a bare ${x} and split its joined result: GNU 5.3.0 gives ["p]/[q"], master gave one ["p q"] field. - H${$+<newline>}H - the unquoted expansion result must field-split at the newline: GNU prints 'Unquoted: H H' on one line, master printed two lines. - ${assoc[@]@k} - the transform's trailing separator must fall off through the unquoted field split (GNU drops it unquoted and keeps it in the quoted face). When the introducer itself is quoted ("${x}"), the span's result never field-splits, so the scan keeps skipping the body. The eligibility re-enable also re-armed #743's quoted-segment IFS protection for words whose escaped quotes the marking simulation mis-modeled: the lexer cooks an escaped quote OUTSIDE any quote span to its data-quote marker (single-quote escapes to 0x17, double-quote escapes to 0x18), and the simulation must reproduce that or it bails and a quoted blank loses its protection (a replacement word with escaped-quote affixes plus a quoted trailing space lost that space, part_063). Model the two spellings; span-internal backslashes stay verbatim pairs. Snapshot re-recorded per the tests/regression.rs protocol (this commit is the named engine change): exp.snap's X${c}X face now splits XY/YX under IFS=0x01 exactly like GNU bash (the committed golden had encoded the pre-#789 no-split divergence; WSL GNU 5.3.0(1)-release probe, 2026-10-13). nquote.snap intentionally stays at master's version: its trailing `foo` line is the GNU-consistent nquote4.sub alias face under the #812 suite driver, and the no-foo golden was the CRLF-era divergence already adjudicated in #803 - carrying this fix's transient recording forward would resurrect those bytes. New GNU-verified differential pins: arrdefault_quoted_array_default_regressions:: escaped_quote_guard_class_splits_vs_gnu and parameter_transform_tests:: test_parameter_transform_at_k_trailing_separator_splits_away_unquoted.
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.
Closes #743
问题
像
a$w"b"这样的混合词(部分引用、部分未引用),GNU bash 会对未引用部分的展开结果做 field splitting,但 rubash 用词级的raw_word_is_quoted判断——词里只要出现引号就整词跳过 splitting。根因
splits_unquoted_expanded_word用词级引号标记判断整个词,太粗。GNU 是按字符跟踪引号状态的(parse.y read_token_word;subst.c:11639-11673 对引号内源码字符做 CTLESC 保护)。改动
src/executor/command_words.rs:新增raw_word_has_unquoted_parameter_expansion_outside_quotes(),按字符跟踪引号状态,只当展开出现在引号之外时才认定可 split。src/executor/command_prepare.rs:needs_ifs_marking去掉门控;新增mark_quoted_ifs_from_raw();mark_literal_ifs_chars跳过 $'...' span。src/executor/markers.rs:引入 E400-aware helper(完整版在 user-typed PUA codepoints collide with the marker registry: ANSI-C E401 is silently swallowed (data loss); E301/E314 miscount as length 2 #735)。验证
issue 的 2 个 case + 9 个扩展 probe 与 GNU bash 逐字节一致。
注意
本 PR 功能上依赖 #735,建议先合 #735。