Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow escaping "$" in command arguments #505

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rkennedy
Copy link

@rkennedy rkennedy commented May 1, 2024

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

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 sequence "\\" 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 magefile#434
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exec args always expanded
1 participant