echo escape conformance: xpg_echo + the \0nnn octal rule (batch83) - #284
Merged
Conversation
bash's echo (with -e, and with xpg_echo) accepts only the \0nnn octal escape; a bare \1..\7 is left literal, unlike printf's %b which does interpret \nnn (echo.def vs printf.def). gnash's shared decode_b interpreted the bare form in both, so `echo -e "\101"' printed `A' instead of the literal `\101'. Add a bare_octal parameter (default true, preserving printf %b) and pass false from echo, so a bare \nnn stays literal there while \0nnn still decodes.
`shopt -s xpg_echo' should make echo interpret backslash escapes by default, as if `-e' were given (bash echo.def: do_v9 = xpg_echo). gnash recognized the shopt name but never acted on it. Initialize echo's escape interpretation from xpg_echo, and -- matching bash's `posixly_correct && xpg_echo' short-circuit -- skip option parsing entirely in POSIX mode with xpg_echo, so -n/-e/-E are then printed literally. Closes #283.
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
Two related
echoescape-handling fixes surfaced bybuiltins2.sub(builtinsbyte-diff 179 → 172, no regressions).1. echo octal is
\0nnn, not a bare\nnnbash's
echo(with-e, and withxpg_echo) accepts only the\0nnnoctal escape; a bare\1..\7stays literal — unlikeprintf %b, which interprets\nnn. gnash's shareddecode_binterpreted the bare form in both, soecho -e "\101"printedAinstead of literal\101. Added abare_octalparameter (default true, preservingprintf %b) and pass false fromecho.2. honor the xpg_echo shopt
shopt -s xpg_echonow makesechointerpret backslash escapes by default (as if-e), matching bash (do_v9 = xpg_echo). In POSIX mode with xpg_echo, option parsing is skipped entirely so-n/-e/-Eprint literally (bash'sposixly_correct && xpg_echoshort-circuit). gnash previously recognized the shopt name but ignored it.Testing
builtins179 → 172, zero regressions across the full suitebuiltins2.subnow matches bash byte-for-byte; verified octal/hex/xpg/posix cases against bash 5.3Closes #283.