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

Alias does not pass quoted parameters correctly to the external command (shell) #2653

Closed
otanner opened this issue Jun 9, 2017 · 3 comments · Fixed by #2689
Closed

Alias does not pass quoted parameters correctly to the external command (shell) #2653

otanner opened this issue Jun 9, 2017 · 3 comments · Fixed by #2689
Assignees
Labels
bug This issue is a bug.

Comments

@otanner
Copy link

otanner commented Jun 9, 2017

Hi,

When using a shell function in aliases the parameters are not quoted correctly.

Here is a simple alias for testing (~/.aws/cli/alias):

[toplevel]

test-quotes =
  !f() {
    for i in "$@"; do
        echo "$i"
    done
  }; f

Testing the alias with aws test-quotes foo bar "foo bar":

Desired output:

foo
bar
foo bar

Actual output:

foo
bar
foo
bar

When debugging the ExternalAliasCommand's __call__ method the command_components variable contains ['f() {\nfor i in "$@"; do\necho "$i"\ndone\n}; f', 'foo', 'bar', 'foo bar'] so the quoted parameter with a space is parsed correctly on input.

However when making the actual function call the parameter is not quoted correctly: Using external alias 'test-quotes' with value: '!f() {\nfor i in "$@"; do\necho "$i"\ndone\n}; f' to run: 'f() {\nfor i in "$@"; do\necho "$i"\ndone\n}; f foo bar foo bar'

One fix could be to use quote function from https://pypi.python.org/pypi/shellescape (backport of Python shlex.quote for Python versions 2.x & < 3.3) for args to get arguments escaped correctly but this creates a new dependency. (something like command_components.extend(map(quote, args)))

Version info: CLI version: aws-cli/1.11.101 Python/2.7.13 Darwin/16.5.0 botocore/1.5.64

@JordonPhillips
Copy link
Member

Can confirm. I compared this to how git aliases work and they do as you expected. Thanks for reporting!

@JordonPhillips JordonPhillips added the bug This issue is a bug. label Jun 9, 2017
@JordonPhillips
Copy link
Member

This could probably be fixed by using shlex.quote, but I'm not sure that will work with Windows so well.

@otanner
Copy link
Author

otanner commented Jul 10, 2017

I can confirm the fix is working as expected on my setup as well. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants