Skip to content

fix: land local master batch — heredoc warnings, arithmetic messages, ifs multibyte, printf locale, raw-byte markers, let $var - #110

Merged
caomengxuan666 merged 12 commits into
masterfrom
rescue/local-master-batch
Sep 16, 2026
Merged

caomengxuan666 merged 12 commits into
masterfrom
rescue/local-master-batch

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Rescue publication of the 12 commits accumulated on the local shared checkout's master (base 9729b14), rebuilt 1:1 via the GitHub API (original messages and per-commit granularity preserved; hashes differ by construction).

Contents:

  1. fix: ANSI-C quote non-printable command names in not-found errors
  2. fix: duplicate "syntax error near" prefix in case command parse error
  3. fix: heredoc EOF warning for command substitutions with `)` on delimiter line
  4. fix: heredoc warning line numbers for command substitutions and trailing newline
  5. fix: arithmetic error messages for compound division, ternary, pre-increment
  6. fix: post-increment assignment error message (x++=7, x--=7)
  7. fix: duplicate "syntax error near" prefix for arithmetic parse errors
  8. fix(harness): install en_US.UTF-8 locale in true-baseline.sh
  9. fix(printf): locale-aware decimal point for printf %f
  10. fix(ifs): multibyte character splitting respects UTF-8 boundaries
  11. fix(raw-byte): preserve marker pairs through storage and ANSI-C decode
  12. fix(arith): let preserves \$var tokens and reports operand expected

Note for the owning session: after this merges, the local master needs `git pull --rebase` (or re-push with --force-with-lease after rebasing) since the remote copies have new hashes.

GNU execute_cmd.c:5909 calls printable_filename (general.c:1019) before
printing "command not found", which uses ansic_shouldquote/ansic_quote to
convert non-printable characters to $'...' form. A CR-only command name
(from a CRLF line ending) now reports `$'\r': command not found` instead
of a raw control character or empty name.

- arrays.rs: re-export ansic_quote and ansic_shouldquote from storage.
- execution_misc.rs: add printable_filename helper matching GNU general.c.
- external_inner.rs, pipeline_stages.rs: apply printable_filename to
  command names in all "command not found" error messages.

Verification:
- cargo build: succeeds
- cargo test --lib: 397 passed, 0 failed
- iquote suite: stderr 14→0 (CR command names now ANSI-C quoted)
- Remaining 4-line stdout diff is a separate DEL handling issue

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
case_command.rs stored the full "syntax error near unexpected token `)'"
in __RUBASH_PARSE_ERROR__, but command_execute.rs already prepends
"syntax error near" when printing the message, producing doubled output.
Store only "unexpected token `)'" so the prefix is added once.

Verification:
- cargo build: succeeds
- cargo test --lib: 397 passed, 0 failed
- posix2 suite: stderr 4→0

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ter line

GNU make_cmd.c:602-611: when the `)` closing a command substitution sits
on the heredoc delimiter line (e.g. `EOF)`), the heredoc is "delimited
by end-of-file" and a warning is issued. Previously Rubash missed this
warning entirely.

Changes:
- lexer/mod.rs: When the comsub closes (`)` on delimiter line), insert
  \x1c marker before `)` in the logical line so the executor can detect
  this case. Only triggers when `)` is on the delimiter line, not the
  header line (e.g. `cat << EOF)` is a different case).
- command_substitution_pipelines.rs: Pass __RUBASH_CURRENT_LINE as
  start_line to tokenize_comsub_body so warning line numbers match GNU.
  Add deduplication via last_heredoc_warning_source RefCell to prevent
  duplicate warnings when the same comsub is expanded through multiple
  paths (expand_assignment_value_inner and expand_embedded_parameters_mut).
- command_substitution_pipelines.rs: Remove duplicate warning from
  command_substitution_heredoc_output (non-typed path).
- executor/mod.rs, init.rs, command_substitution.rs: Add
  last_heredoc_warning_source RefCell field for deduplication.
- assignment_expansion.rs: Restore \x18/\x17 data-quote markers in
  assignment value fast path (niubash#103 regression fix from G91 agent).

Verification:
- cargo build: succeeds
- cargo test --lib: 397 passed, 0 failed
- heredoc suite: stderr 32→28 (4 warnings now correctly emitted)
- Remaining diffs: platform noise (touch/cmp paths) + deeper heredoc
  edge cases (line 98 warning, heredoc7 line number offset)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ing newline

Two fixes for heredoc EOF warning line numbers:

1. lexer/mod.rs: Skip trailing empty line from split('\n') in heredoc
   body collection. Without this, an unterminated heredoc at EOF gets
   an extra empty body line, making the warning line number off by 1
   (reported line 3 instead of line 2 for comsub-eof2.sub).

2. command_substitution_values.rs: Use start_line (command.line, which
   accounts for leading newlines in the comsub source) instead of
   current_line (__RUBASH_CURRENT_LINE, the outer command line) for
   warning_line computation. When `$(` is at end of line, the comsub
   body starts on the next line, and the warning should reference that
   line, not the outer command line.

3. embedded_mutations.rs: Count leading newlines in comsub source and
   store in comsub_leading_newlines Cell for the heredoc path.

4. command_substitution_pipelines.rs: Adjust comsub_start_line by
   comsub_leading_newlines so tokenize_comsub_body sets correct line
   numbers.

5. mod.rs, init.rs, command_substitution.rs: Add comsub_leading_newlines
   Cell field.

Verification:
- cargo build: succeeds
- cargo test --lib: 397 passed, 0 failed
- heredoc suite: stdout 0 diff, stderr 32→27
- comsub-eof suite: stdout 0 diff, stderr 17→9
- Remaining diffs: platform noise (touch/cmp paths), comsub-eof3.sub
  missing warning, comsub-eof6.sub format, heredoc7.sub line offset

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…crement

Align arithmetic error messages with GNU expr.c:

1. arithmetic_division_by_zero_token: Handle compound assignment operators
   `/=` and `%=`. `b /= 0` now reports "division by 0" instead of
   "syntax error in expression" (expr.c:552, 917).

2. missing_ternary_colon_token: New function to detect ternary `?` without
   matching `:`. `1 ? 20` now reports "`:' expected for conditional
   expression" instead of "syntax error in expression" (expr.c:649-654).

3. empty_ternary_true_branch_token: New function to detect ternary `?` with
   empty true-branch. `4 ? : $A` now reports "expression expected" instead
   of "arithmetic syntax error in expression" (expr.c:647).

4. pre_increment_assignment_token: New function to detect `--x=7` / `++x=7`.
   Pre-increment returns a value, not an lvalue, so the `=` is "attempted
   assignment to non-variable" (expr.c:529).

5. pre_post_increment_lvalue_token: New function to detect `--x++` / `++x--`.
   Pre-increment returns a value, not an lvalue, so the post-increment fails
   with "++: assignment requires lvalue" (expr.c:1465-1471).

Verification:
- cargo build: succeeds
- cargo test --lib: 397 passed, 0 failed
- arith suite: stderr 75→65 (10 lines improved), stdout 50 (unchanged)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
GNU expr.c:529: post-increment/decrement returns a value, not an lvalue,
so the following `=` is "attempted assignment to non-variable". Previously
only pre-increment (--x=7, ++x=7) was handled; now post-increment
(x++=7, x--=7) is also caught.

Verification:
- cargo build: succeeds
- cargo test --lib: 397 passed, 0 failed
- arith suite: stderr 65→59, stdout 50 (unchanged)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
When __RUBASH_PARSE_ERROR__ is set to "arithmetic syntax error: operand
expected" (from parser/support.rs array element assignment with escaped
quotes), command_execute.rs was adding "syntax error near" prefix because
the message didn't start with "syntax error:". Now also check for
"arithmetic syntax error:" prefix.

Before: "syntax error near arithmetic syntax error: operand expected"
After: "arithmetic syntax error: operand expected"

Verification:
- cargo build: succeeds
- cargo test --lib: 397 passed, 0 failed
- arith suite: stderr 59 (unchanged count, but 4 lines fixed from duplicate
  prefix to correct message; remaining diffs need expression/token in error)

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
intl.tests/unicode*.sub require en_US.UTF-8 for proper multibyte char
counting. Without it, GNU bash emits "warning: setlocale: LC_ALL: cannot
change locale" and falls back to C locale (byte counting), producing a
broken baseline that inflates intl diff by ~57 lines of pure environment
noise. The script now runs `locale-gen en_US.UTF-8` if the locale is
missing and exports LC_ALL=en_US.UTF-8 so the GNU side matches intl.right.

Effect: intl 82 -> 25 diff lines (57 lines of locale noise removed).
The remaining 25 lines are real Rubash carrier-byte/ANSI-C quoting issues.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
GNU snprintf.c:439-445 calls localeconv() and replaces the `.` in
rendered floating-point output with localeconv()->decimal_point[0].
In de_DE.UTF-8 this is `,`, so `printf '%.4f' 1` outputs `1,0000`.

Add crate::locale::decimal_point() that returns the locale-aware
decimal separator (LC_NUMERIC > LC_ALL > LANG priority), and apply
it in format_float() after rendering.

Also install de_DE.UTF-8 in true-baseline.sh so intl2.sub's LC_NUMERIC
tests have the required locale available.

Effect: intl 27 -> 25 (2 lines fixed: the `1,0000` outputs now match).
The remaining `1.0000` vs `5` difference is /usr/bin/printf not
existing on the Windows side (environment, not rubash bug).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
GNU subst.c:1148-1250 (string_extract_verbatim) walks the string
byte-by-byte, uses mbrtowc to identify multibyte character boundaries,
and checks each complete character against the IFS character list via
wcschr. A multibyte character like € (U+20AC, bytes E2 82 AC) is never
split even if one of its bytes appears in IFS.

Rubash stores bytes >= 0x80 as U+E000 + U+E0xx marker pairs inside Rust
Strings. The previous char-level `ifs.contains(ch)` would falsely match
the marker sentinel U+E000 when both the value and IFS contained
raw-byte markers (e.g. IFS=$'\254' splitting € which contains byte AC).

Add field_split_with_raw_byte_markers() that decodes both sides to raw
bytes, walks the value respecting UTF-8 character boundaries, and
re-encodes the result. This matches GNU's mbrtowc + wcschr approach.

Effect: intl 25 -> 23 (IFS multibyte splitting in intl3.sub now correct).
Rust tests: 388 passed, 0 failed.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Control characters that are assignment carrier bytes (0x0c, 0x11, 0x13,
0x14, 0x16, 0x17, 0x18, 0x1a, 0x1b, 0x1c, 0x1d, 0x1f) must be encoded
as raw-byte markers to match the ANSI-C lexer's push_ansi_c_byte
encoding. Without this, `printf -v r '\U00000013'` stores raw char
\x13, but `$'\023'` stores a marker pair — they compare unequal
(unicode1.sub: EChar != RChar) and `$r` expansion strips the raw
char (len=0, %q='').

Also preserve raw-byte marker pairs through unquote_storage_value
instead of decoding them, so carrier bytes survive the expansion
path and are decoded at the final output stage.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
GNU let.def::let_builtin passes EXP_EXPANDED to evalexp, meaning the
arithmetic evaluator does NOT expand \$var. In GNU expr.c::readtok,
legal_variable_starter(c) is ISALPHA(c) || (c == '_'), so '\$' is not
a valid operand character. When the evaluator sees '\$var' after an
operator, it reports "operand expected" with the '\$var' token.

Rubash previously expanded \$var before arithmetic evaluation in all
contexts, so `let 'jv += \$iv'` succeeded (jv += 0) instead of failing.

Changes:
- Add no_expand flag to ConditionalArithParser and eval_mutable_arith_*
  functions, propagated through eval_arithmetic_command_value_with_flags
- execute_let uses eval_arithmetic_command_value_no_expand to preserve
  \$var references for the arithmetic evaluator
- Add dollar_var_operand_token helper to detect \$var in let expressions
  and report "operand expected" with the original token (including
  trailing whitespace, matching GNU's lasttp)
- Remove debug instrumentation left by previous agents in
  declare/assign.rs, declare/storage/array.rs, arrays.rs,
  arrays/storage.rs, assignment_expansion.rs
- Keep real fixes from previous agents: hex/octal subscript support
  (declare/storage.rs), compound assignment backslash preservation
  (assignment_expansion.rs), array value identity roundtrip
  (arrays/storage.rs)

Verification:
- cargo build: clean (1 pre-existing warning)
- cargo test --lib: 397 passed, 0 failed
- arith stderr: 58 -> 57 (let \$iv cases now match GNU)
- Targeted probes match GNU for let \$iv, let \$iv (trailing space),
  (( \$var )), let missing )

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit 9ac6170 into master Sep 16, 2026
3 checks passed
@caomengxuan666
caomengxuan666 deleted the rescue/local-master-batch branch September 16, 2026 03:42
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