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.97k stars 332 forks source link

syntax: converting a backtick command substitution with escaped characters leaves too many backslashes #1041

Closed nicki-krizek closed 6 months ago

nicki-krizek commented 8 months ago

shfmt 3.7.0 incorrectly escapes backslashes in the following example:

### input
x=`echo "1.2" | sed -e 's/\./\\\\./g'`
echo $x # prints out 1\.2

### actual output
x=$(echo "1.2" | sed -e 's/\./\\\\./g')
echo $x # prints out 1\\.2

### expected output
x=$(echo "1.2" | sed -e 's/\./\\./g')
echo $x # prints out 1\.2
mvdan commented 7 months ago

Thanks - this sounds like a bug. We probably never noticed given that it's a relatively rare edge case. Happy to review a PR with a test.