Do not parse aliases in POSIX mode when passing to shell

Review Request #10149 — Created Sept. 19, 2018 and submitted — Latest diff uploaded

Information

RBTools
release-0.7.x
07a2ccb...

Reviewers

We are using shlex.split to 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' -delete would be
evaluated into find . -iname *.pyc -delete run by the shell, which
would result in the *.pyc being evaluated by the shell instead of by
find.

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_arguments also now returns a
list instead of a generator because we were always immediately wrapping
it in a call to list anyway.

  • Ran unit tests.
  • Ran rbt clear-pycs with .pyc files in the current directory. All
    .pyc files were recursively removed.
    Loading...