Repository navigation
fix(invocation): #705 R7.1-R7.3 (errexit nounset rc, --, argument-less -o listing) - #778
Merged
Merged
Conversation
R7.1: the fatal word-expansion error (`set -u` word, `${var?}`, nounset arithmetic) exits 127 at the `-c` top level because shell.c:1471 run_one_command remaps the FORCE_EOF jump. GNU only reaches that remap with errexit OFF: error.c:169 report_error, when exit_immediately_on_error is set (flags.c:263), calls exit_shell(last_command_exit_value) — an EXITPROG jump with EXECUTION_FAILURE (1). So `bash -eu -c 'echo $UNDEF'` exits 1 while `bash -u -c 'echo $UNDEF'` exits 127, and the option value at the error site decides (an `if`/`||` context does not clear it).
expansion_fatal_status now reads errexit_enabled() in the __RUBASH_IS_C arm.
Tests: tests/issue705_nounset_errexit_status.rs compares the `-eu`/`-u` matrix byte-for-byte with WSL GNU bash 5.3.0.
…ng (#705) R7.2: GNU shell.c:905-911 ends option parsing on a lone `-` or `--`; the next word is the script and, with none, the shell reads stdin (shell.c:780-786). ShellInvocation::parse rejected `--` with no operand (`--: option requires a script`) and a lone `-` fell to the invalid-option arm, so the niu host errored where `bash --` reads stdin. R7.3: shell.c:931-938 treats `-o`/`+o` with no following word as the LIST form (list_minus_o_opts), prints the table and continues — not a usage error. The parser now records the request so the table renders during option application (the engine binary already listed through its own parser, rubash#547); `-o <name>` is unchanged. write_shell_options_listing exposes the exact bytes for hosts and tests. Tests: tests/issue705_dashdash_separator.rs and tests/issue705_option_list.rs pin the parser contract and the engine routes; the `-o` table bytes match WSL GNU bash 5.3.0.
caomengxuan666
added a commit
that referenced
this pull request
Oct 17, 2026
…redicate (#738 #780 #727) Three open-issue fixes from the 2026-10-17 sweep. #738 heredoc delimiter was dequoted by DELETING the quote characters: `<<E\'OF` named `EOF`, the terminator `E'OF` never matched, and the heredoc ran to end-of-file — silently consuming the rest of the script with rc 0 and a warning most scripts never read. Four sites did `replace(['\'','"','\\'], "")`. New `lexer::heredoc_scan::dequote_heredoc_delimiter` implements GNU `string_quote_removal` (an escaped character stays literal, a quoted run keeps its bytes, double-quote backslash rules); skip.rs / heredoc_scan.rs / execution_misc.rs / alias_stream.rs all route through it. The word token also carries an escaped quote/backslash as DATA_SQUOTE / DATA_BACKSLASH, so `heredoc_delimiters` decodes those carriers before comparing body lines. #780 argument-less `-O`/`+O`: GNU shell.c routes it to the shopt table (`-O` = the `shopt` bytes, `+O` = the `shopt -p` bytes), rc 0 — the sibling of the `-o`/`+o` case fixed in #547/#778. ShellInvocation gains `list_shopt_options` + `write_shopt_options_listing`, and both the engine parser and `parse_post_c_option` take the list form instead of a usage error. #727 the golden marker-leak assertion scanned lead byte 0xEF: U+E000..=U+EFFF is 0xEE (0xEF starts U+F000). It therefore could not see any registered marker and only ever fired on user data. Fixed, plus two self-tests (a registered marker must be caught; U+F000 must not). With the predicate finally live, `xtrace_carries_no_markers` had to stop asserting "no PUA" on output that IS user PUA — it now asserts the literal round-trip (one char per traced word, no E400 escape, no named marker). Tests (all four run in the windows-latest regression job): heredoc_delimiter_with_escaped_quote_or_backslash_terminates argument_less_capital_o_prints_the_shopt_listing marker_leak_golden::pua_assertion_sees_a_registered_marker marker_leak_golden::pua_assertion_ignores_the_f000_block Lib 609 passed. Regression: the three failures this tree shows (golden_fnbody_strict_battery's stale `array-y` golden, and the two yes|head SIGPIPE canaries) reproduce identically on the pristine parent.
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.
Summary
Fixes the three unambiguous items of #705 and reports the fourth (branding) as an open product-copy call. Every item was re-checked on current
origin/master(7490feb0) against WSL GNU bash 5.3.0(1)-release (/usr/local/bin/bash), file-based.Boundary note: the reporter invoked
niu(the launcher), which reaches the engine throughrubash::invocation::ShellInvocationandrubash::executor. This PR fixes the engine/lib surface; two of the user-visible symptoms also need the thin launcher's script-open path, called out below.Per item
R7.1
-eunounset exit status — reproduced, fixedbash -eu -c 'echo $UNDEF'bash -u -c 'echo $UNDEF'bash -u -c 'set -e; echo $UNDEF'bash -eu -c 'set +e; echo $UNDEF'bash -eu -c 'echo ${X?}'bash -eu -c 'echo $((NOPE))'bash -eu -c 'false || echo $UNDEF'bash -eu script(echo $UNDEF)Root cause, from the vendored C source: shell.c:1471
run_one_commandonly remaps the nounsetFORCE_EOFjump to 127 with errexit off. Withexit_immediately_on_errorset (flags.c:263), error.c:169report_erroritself callsexit_shell(last_command_exit_value)— anEXITPROGjump withEXECUTION_FAILURE(1) — so the 127 remap is never reached. The predicate is the option value at the error site, so a||/ifcontext does not clear it (verified on the oracle).expansion_fatal_statusnow readserrexit_enabled()in the__RUBASH_IS_Carm. Diagnosis unchanged:bash: line 1: UNDEF: unbound variable.R7.2
--separator — partly reproduced, partly already fixedprintf 'echo X\n' | bash --X, rc 0X, rc 0read_stdinsetbash -- nosuch.sh…: nosuch.sh: No such file or directoryniu --X, rc 0bash: --: option requires a script, rc 2read_stdinsetniu -- nosuch.shniu: …️(os error 2), rc 1ShellInvocation, where--with no operand was rejected.ShellInvocation::parsenow ends option parsing on a lone-/--(shell.c:905-911), takes the following word as the script and otherwise setsread_stdin(shell.c:780-786). This also fixes the lone-form, which previously fell through to the invalid-option arm.niu -- nosuch.shfails in the launcher'srun_shell_invocationscript branch, which doesstd::fs::read_to_string(...)?and surfaces the raw localized OS error with rc 1. The engine's own path already prints the normal…: nosuch.sh: No such file or directory+ 127. The launcher should route---introduced scripts through its existing missing-script handling (niu: <name>: No such file or directory, rc 127) instead of the?.R7.3
niu -owith no argument — reproduced, fixed (lib route)bash -oname\tstatetable, rc 0bash: -o: option requires an argument, rc 2bash +oset +o …recreate list, rc 0bash -o pipefailshell.c:931-938 routes the argument-less
-o/+otolist_minus_o_optsand keeps parsing; it is not a usage error.ShellInvocationnow records the request (list_shell_options) and emits the table during option application, so a host that applies the invocation gets GNU's bytes with no host change;write_shell_options_listingexposes the exact output for tests. Flags parsed before the request are applied first, matching GNU's left-to-right walk.Adjacent, unreported and left alone:
-O/+Owith no argument still errors in both the engine and the lib.bash -Oprints the shopt table, rc 0.R7.4 error-message branding — open, product-copy call
Current bytes, GNU vs the reporter's
niu1.4.0 vs this engine. Exit codes and streams otherwise match.rubash)bash: line 1: nosuchcmd: command not foundniu: line 1: …bash: line 1: …(match)bash: -c: line 2: syntax error: unexpected end of file from \if' command on line 1`niu: -c: line 2: …bash: line 1: NOPE: unbound variableniu: line 1: …bash: line 1: …(match)bash: line 1: exit: too many argumentsrubash: exit: too many argumentsrubash: exit: too many argumentsbash: --bogus: invalid optionbash: --bogus: invalid optionbash: line 0: bash: bogusopt: invalid option namebash: line 0: bogusopt: invalid shell option nameTwo things are entangled and need an owner decision:
$0-vs-product prefix. GNU'serror.c get_name_for_errorderives the prefix from$0; a shell invoked asniuwould printniu:. But the engine's compiled-inexitbuiltin hardcodesrubash:(src/builtins/exit.rs:64), and its other diagnostics print the canonicalbash:. So the product currently mixesniu:/rubash:/bash:across paths. Should the engine's own diagnostics stay canonicalbash:(script/test keying) or follow the invocation face?line N:segment. GNU'sexit: too many argumentscarriesline 1:; the engine's does not. That part is not branding and can be fixed independently once (1) is decided.Per the ticket this is cosmetic; not changed here because it is a product-copy call. The niu-side rows are the launcher's and are out of this repo.
Tests
tests/issue705_nounset_errexit_status.rs—-eu/-umatrix (word,${x?}, arithmetic,set -e/set +e,||, script mode, subshell), exit statuses compared with WSL GNU bash 5.3.0; diagnostic bytes pinned.tests/issue705_dashdash_separator.rs— parser contract for-/--with and without an operand, plus engine routes (piped stdin, missing script → 127, script + positionals).tests/issue705_option_list.rs— argument-less-o/+oparse and listing bytes (matchesset -o/set +o), flags-before-list ordering, named form unchanged, engine-o/+oroutes.All three sandbox the CWD under the system temp dir.
cargo fmt --checkclean;cargo test --lib689 passed; the existing invocation/errexit/nounset suites (issue585/590/591/626,issue154/307/311/319/358/529/535/547/637/638/639,cli_tests errexit::*) pass.