-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: stop using shlex.split() and use lists instead
Stop using `shlex.split()` in conftest.py as a way to prepare test commands for subprocess.run() because it does not always work. When we have quoting issues, just avoid them entirely by passing the test command as a list. Replace shlex.split() with a simple str.split() for convenience in simple cases. This simple split() will immediately fail when trying to use quote which is working exactly as intended. This also makes the cmd() interface more similar to subprocess.run() and its many friends, which is good thing. This is similar to commit 4100764 ("Project.git(list/str): reduce reliance on shlex.split()") but applied to tests/ Before commit 624880e, shlex.split() was used unconditionally in conftest.py. As expected, this eventually broke on Windows: shlex is not compatible across all operating systems and shells. https://docs.python.org/3/library/subprocess.html#security-considerations > If the shell is invoked explicitly, via shell=True, it is the > application’s responsibility to ensure that all whitespace and > metacharacters are quoted appropriately to avoid shell injection > vulnerabilities. On _some_ platforms, it is possible to use shlex.quote() > for this escaping. (Emphasis mine) Then commit 624880e made the "interesting" decision to stop using shlex.split()... only on Windows. This was discussed in #266 (comment) So after this commit, parsing of test commands was delegated to the shell but... only on Windows! This worked for a long time but eventually broke testing white spaces for the new `west alias` #716. Rather than making that Windows-specific hack even more complex with a special case, finally do the right thing and ask more complex test commands to use a list. Now we can drop shlex. Signed-off-by: Marc Herbert <marc.herbert@intel.com>
- Loading branch information
Showing
2 changed files
with
57 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters