From c9e9e24e240ed3c0014aa2e8948c7d56544b744f Mon Sep 17 00:00:00 2001 From: neil Date: Wed, 21 Oct 2026 20:22:33 +0800 Subject: [PATCH] _json_encode: fix empty output on Solaris, newline loss in _hex_dump fallback _hex_dump strips the trailing newline, and Oracle Solaris sed drops an unterminated last line, so the sed step in _json_encode produced nothing and every caller got an empty string on Solaris. Capture the hex first and re-emit it with printf "%s\n". The _ascii_hex fallback of _hex_dump (used when od/hexdump/xxd are not in PATH, e.g. Tribblix) captured stdin with $(cat), losing trailing newlines, and ran cut -c per line, so multi-line input was mis-encoded. Process the input line by line instead. Both surfaced by le_test_json_encode (#7212). --- acme.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/acme.sh b/acme.sh index 1505d1b3..0b4d6d28 100755 --- a/acme.sh +++ b/acme.sh @@ -666,8 +666,15 @@ _hex_dump() { xxd -ps -c 20 -i | sed "s/ 0x/ /g" | tr -d ",\n" | tr -s " " else _debug3 "using _ascii_hex" - str=$(cat) - _ascii_hex "$str" + #line by line: the cut -c in _ascii_hex works per line, and a $(cat) + #capture would drop the trailing newlines (illumos without od in PATH) + while IFS= read -r _hd_line; do + _ascii_hex "$_hd_line" + printf " 0a" + done + if [ -n "$_hd_line" ]; then + _ascii_hex "$_hd_line" + fi fi } @@ -909,7 +916,10 @@ _json_encode() { _debug3 "_j_str" "$_j_str" #printf, not echo: dash's echo interprets backslash escapes and would #collapse the \\ sequences (e.g. Telegram MarkdownV2 escapes, issue 7212) - printf "%s\n" "$_j_str" | _hex_dump | _lower_case | sed 's/0a/5c 6e/g' | tr -d ' ' | _h2b | tr -d "\r\n" + _j_hex="$(printf "%s\n" "$_j_str" | _hex_dump | _lower_case)" + #the hex line must end with a newline: Solaris sed drops an unterminated + #last line, which emptied the whole output + printf "%s\n" "$_j_hex" | sed 's/0a/5c 6e/g' | tr -d ' ' | _h2b | tr -d "\r\n" } #from: http:\/\/ to http://