mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
6.99k stars 333 forks source link

interp: implement %b for printf builtin #955

Closed reubeno closed 1 year ago

reubeno commented 1 year ago

Update printf implementation to do the same as echo -e for the %b format specifier: expand backslash escape sequences in the provided argument but not % format specifiers.

Extracts inner logic from Format into formatIntoBuffer to avoid issues with non-reentrancy of Format (due to use of a special cached buffer in Config.


Request for feedback

This was the simplest change that I could see, but I wasn't thrilled about having formatIntoBuffer recursively call itself for the %b case; this shouldn't generally be problematic, since the recursive call won't process % format specifiers and shouldn't further recur.