Repository navigation
fix(echo): accept -e, -E and combined -neE option words - #211
Conversation
b762609 to
283b454
Compare
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve. The option parsing matches bash on every case I tried, and the new tests prove the fix: 14 of the 18 fail on main and pass here. Nothing in this PR is blocking.
Two non-blocking follow-ups:
- Docs will go stale (harness-sdk).
site/src/content/docs/user-guide/shell/commands.mdxsays: "echo| Expands escapes by default;-eand-Eare printed literally (escape expansion cannot be disabled)." After this merges, both halves are wrong. That file lives in another repo, so it needs a separate docs PR. - Question:
-eis now honored, butexpand_escapes(src/builtins/echo.rs:55) has no\xor\u(and no\e). Soecho -e 'a\x41b'printsa\x41b; bash printsaAb. This was already true onmain.printf::escape_all(src/builtins/printf.rs:360) already handles\x/\u. Could echo reuse it in a follow-up?
What I verified
- Head
283b454.cargo test --test shell_integration: 1642 passed.cargo test --test differential: passed. - With
src/builtins/echo.rsreverted tomainand the PR's tests kept, 14/18echo_opt_*tests fail and the differential test fails. The other 4 (-x,-nx,--,-) guard against regressions. Removing theknown-differencemarker fromecho_e.shis correct. - I compared 28 commands through
bash -candstrands-shell -c(byte-level,od -c). 27 match, including:-ne,-eE,-E -e,-neEx,-enen,-e-n,'' -n x,x=-e; echo $x …, quoted"-n",-Ewith\c,-ewith\0101, multi-byte args, pipes, and$(echo -ne k). The one mismatch is the\xcase above. - Other call sites:
command echo,builtin echo,/bin/echo,xargs echo -e, andfind -exec echo -eall reach the builtin and match bash.src/commands/echo.rsis a lexopt-based echo that rejects-n/-e, but builtins are looked up first (src/exec.rs:3276,:3541), so none of these paths reach it. - Nit: the PR fixed the stale "echo -e is not supported" comment, but
tests/shell_integration.rs:3969still has the header// ── echo -e escape sequencesabove aprintftest.
|
Thanks for checking the regressions against main. Agreed that the command table in harness-sdk needs a separate docs update; this PR changes option parsing and keeps the existing default escape behavior. Sharing escape handling makes sense as a follow-up, with explicit echo/printf rules. I checked that |
Description
echoonly understood a single leading-n, so anything else got printed as text. For instanceecho -e 'a\tb'printed-e a b,echo -ne xprinted-ne x, and-Edidn't stop escapes from expanding. Agents writeecho -eall the time, so this kept leaking flags into their output.Now
echoreads leading-n,-eand-Ethe way bash does, including combined words like-neand separate ones like-n -e, and the last of-e/-Ewins. Words like-x,-nxor--are still printed as text, same as bash. Plainechowith no flags still expands escapes like before; switching it to bash's no-expansion default would be a separate change.I compared each case against bash. The new option tests fail on main and pass with the change, and the full Rust suite passes.
Related Issues
Part of #207
Documentation PR
N/A
Type of Change
Bug fix
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.