Merge pull request #2247 from mfridge/action-command-split

Remove surrounding quotes for quoted command arguments
This commit is contained in:
Nicolas Hennion 2023-01-17 08:04:13 +01:00 committed by GitHub
commit c0524485ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,8 +49,9 @@ def __secure_popen(cmd):
p_last = None
# Split by pipe '|'
for sub_cmd in cmd.split('|'):
# Split by space character, but do no split spaces within quotes
sub_cmd_split = [_ for _ in list(filter(None, re.split(r'(\s+)|(".*?"+?)|(\'.*?\'+?)', sub_cmd))) if _ != ' ']
# Split by space character, but do no split spaces within quotes (remove surrounding quotes, though)
tmp_split = [_ for _ in list(filter(None, re.split(r'(\s+)|(".*?"+?)|(\'.*?\'+?)', sub_cmd))) if _ != ' ']
sub_cmd_split = [_[1:-1] if (_[0]==_[-1]=='"') or (_[0]==_[-1]=='\'') else _ for _ in tmp_split]
p = Popen(sub_cmd_split, shell=False, stdin=sub_cmd_stdin, stdout=PIPE, stderr=PIPE)
if p_last is not None:
# Allow p_last to receive a SIGPIPE if p exits.