Do not parse aliases in POSIX mode when passing to shell
Review Request #10149 — Created Sept. 19, 2018 and submitted — Latest diff uploaded
We are using
shlex.splitto parse aliases, which defaults to a POSIX mode,
which strips quotes and evaluates escape sequences. This lead to issues
where an alias of the form
!find . -iname '*.pyc' -deletewould be
find . -iname *.pyc -deleterun by the shell, which
would result in the
*.pycbeing evaluated by the shell instead of by
Now we operate in POSIX mode only when we are not passing the command
to the shell so shell-specific sequences will be untouched. This results
in aliases not needing double escaping when being passed to the shell.
When not passing to the shell, we still parse in POSIX mode to remove
quotes, etc. because otherwise
subprocess.call()will pass the quoted
strings as arguments (e.g.,
['cmd', '"arg with spaces"']instead of
['cmd', 'arg with spaces']).
While I was here, I also modernized the docstrings of all the alias
methods to our doc standards.
replace_argumentsalso now returns a
list instead of a generator because we were always immediately wrapping
it in a call to
- Ran unit tests.
.pycfiles in the current directory. All
.pycfiles were recursively removed.