Do not parse aliases in POSIX mode when passing to shell
Review Request #10149 — Created Sept. 19, 2018 and submitted
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 intofind . -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 otherwisesubprocess.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 tolist
anyway.
- Ran unit tests.
- Ran
rbt clear-pycs
with.pyc
files in the current directory. All
.pyc
files were recursively removed.
Description | From | Last Updated |
---|---|---|
E303 too many blank lines (2) |
reviewbot | |
E303 too many blank lines (2) |
reviewbot | |
Missing a period. |
david | |
Too many spaces after # |
david | |
typo: decote |
david | |
Extra ` at the end |
david | |
I feel like this would read a little bit more clearly if you swapped them (unicode or list of unicode). |
david | |
Remove this blank line. |
david | |
Typo: veresion -> version |
david | |
This needs a period at the end. |
david | |
Should this be "Quoted tokens"? |
david |
- Summary:
-
Fix alias processing to not mangle quotes in aliasesDo not parse aliases in POSIX mode when passing to shell
- Description:
-
Previously, we were using
shlex.split
, 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 beevaluated into find . -iname *.pyc -delete
run by the shell, whichwould result in the *.pyc
being evaluated by the shell instead of byfind
.~ Now we operate in non-POSIX mode, which returns all tokens in their
~ quotes and does not process escape sequences. These will be handed off ~ to the shell as-is so that aliases do not need double escaping. ~ 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 alist instead of a generator because we were always immediately wrapping it in a call to list
anyway. - Commit:
-
c927aecaed4baaa3e77bfd6c9ec6cea1fd9728ebab3aff9e719bc0418150aad51d83309f74a197a6
- Diff:
-
Revision 2 (+187 -69)
- Change Summary:
-
Fix flake8 errors.
- Commit:
-
ab3aff9e719bc0418150aad51d83309f74a197a64e877ba77e6df795634ad29791c7fd472b6b7509
- Diff:
-
Revision 3 (+185 -69)
Checks run (2 succeeded)
- Commit:
-
4e877ba77e6df795634ad29791c7fd472b6b75096b94000c671588fa2ca333e0df4299fb985be862
- Diff:
-
Revision 4 (+189 -69)
Checks run (2 succeeded)
- Change Summary:
-
Addressed David's feedback.
- Commit:
-
6b94000c671588fa2ca333e0df4299fb985be862f0dc851c23149dbe963fa82bf988633b96a5e4ac
- Diff:
-
Revision 5 (+189 -69)
Checks run (2 succeeded)
- Change Summary:
-
Addressed David's feedback
- Description:
-
~ Previously, we were using
shlex.split
, which defaults to a POSIX mode,~ 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 beevaluated into find . -iname *.pyc -delete
run by the shell, whichwould result in the *.pyc
being evaluated by the shell instead of byfind
.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 quotedstrings 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 alist instead of a generator because we were always immediately wrapping it in a call to list
anyway. - Commit:
-
f0dc851c23149dbe963fa82bf988633b96a5e4acf1644c6a49cf010028fd1e77f2f9590745c999fa
Checks run (2 succeeded)
- Change Summary:
-
Addressed feedback.
- Branch:
-
release-0.7.xrelease-4.0.x
- Commit:
-
f1644c6a49cf010028fd1e77f2f9590745c999faf3b1cc38a3fd3ba64e8901c0a07e9067e49793e6
Checks run (2 failed with error)
- Change Summary:
-
I apparently pushed up a patch from reviewboard to this O_O
- Branch:
-
release-4.0.xrelease-0.7.x
- Commit:
-
f3b1cc38a3fd3ba64e8901c0a07e9067e49793e6f1644c6a49cf010028fd1e77f2f9590745c999fa