You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[bug] ANSI-C escapes not decoded in the replacement operand of ${var//pat/$'\n'}: literal backslash-n stored ($'\t' too; $'\xHH' works) #323
Found by ecosweep3 lane (pure-bash-bible corpus, section 004 'Split a string on a delimiter'; carrier release build of 6106961).
Reproducer (target/probe-out/p3.sh, p9.sh)
s="a,b,c"
r="${s//,/$'\n'}"printf'%s'"$r"| od -An -c
printf'%s\n'"${r@Q}"
GNU bash 5.3.0: a \n b \n c (real newlines); ${r@Q} = $'a\nb\nc'
rubash: a \ n b \ n c (literal 2-char backslash-n); ${r@Q} = 'a\nb\nc' (single-quote form — @q rendering of the literal backslashes)
Matrix (p9.sh): ${s//,/$'\t'} also literal; ${s//,/$x} (plain var) fine; ${s//,/$'\x2e'}correctly decoded to ." — the \xHH path unescapes but \t / \n do not. Argument position echo $'\n'` is unaffected; the bug is specific to the replacement operand of the pattern-substitution expansion.
GNU anchor
The replacement word is expanded as a normal word: subst.c:9777 parameter_brace_expand() → the /pat/repl branch expands repl via expand_word_internal-equivalent paths where $'...' was already decoded at read time by parse.y read_token_word's ANSI-C handling ($'${ handling near parse.y:5530 region, parse_y ansi quoting). rubash's text-layer replacement path re-splits the replacement without the ANSI-C unescape step.
Impact
pbb split() emits apples\noranges\npears as ONE line instead of 4 lines; the $'\n'-as-separator idiom is common in real scripts.
Fixed by wt14/pbbfix (fb91245, master): push_ansi_c_replacement_span had a hand-rolled decoder recognizing only backslash-xHH, backslash-quote and backslash-backslash - now routed through the canonical lexer decoder decode_ansi_c_quoted (GNU: subst.c:4462 -> ansicstr, strtrans.c:51 full table). 22-form matrix (all standard escapes, octal, control-char, unicode, unknown escapes keep the backslash, quote escapes, double-quote-variable literal preservation, @q round-trip) byte-identical.
Activity
fix(#323): patsub replacement $'...' decodes through the canonical AN…
caomengxuan666 commentedon Sep 29, 2026
Fixed by wt14/pbbfix (fb91245, master): push_ansi_c_replacement_span had a hand-rolled decoder recognizing only backslash-xHH, backslash-quote and backslash-backslash - now routed through the canonical lexer decoder decode_ansi_c_quoted (GNU: subst.c:4462 -> ansicstr, strtrans.c:51 full table). 22-form matrix (all standard escapes, octal, control-char, unicode, unknown escapes keep the backslash, quote escapes, double-quote-variable literal preservation, @q round-trip) byte-identical.