magefile / mage

a Make/rake-like dev tool using Go
https://magefile.org
Apache License 2.0
4.01k stars 250 forks source link

Allow escaping "$" in command arguments #505

Open rkennedy opened 2 months ago

rkennedy commented 2 months ago

The sh.Exec family of functions used to use os.Expand to expand environment variables in command arguments, but that function offers no escape syntax — no way to avoid expanding dollar signs that the caller really wants to include on the command line. This commit implements a new, mostly compatible Expand function to allow escaping the environment-variable syntax, plus an accompanying Escape function to producing escaped strings.

This technically breaks backward compatibility; any existing code that has used the sequences "\\" or "\\$" in its command arguments will need to be updated. Although the compatibility argument prevents os.Expand from changing, documentation for sh.Exec hasn't actually stated that it follows all the same rules as os.Expand, so it's possible to view this change as merely a bugfix, formalizing a new syntax that had not previously been established.

Fixes #434