Skip to content

Commit 833f8ee

Browse files
committed
Use a builtin for quoting shell arguments
1 parent 856b2a3 commit 833f8ee

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

osgtest/library/core.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
import traceback
2121
import socket
2222
import signal
23+
try:
24+
from shlex import quote as shell_quote
25+
except ImportError:
26+
from pipes import quote as shell_quote
2327

2428
from osgtest.library import osgunittest
2529

@@ -496,11 +500,6 @@ def __format_command(command):
496500
return result
497501

498502

499-
def __prepare_shell_argument(argument):
500-
if re.search(r'\W', argument) or argument == '':
501-
return "'" + re.sub(r"'", r"'\''", argument) + "'"
502-
return argument
503-
504503
def __run_command(command, use_test_user, a_input, a_stdout, a_stderr, log_output=True, shell=False, timeout=None, timeout_signal='TERM'):
505504
global _last_log_had_output
506505

@@ -514,7 +513,7 @@ def __run_command(command, use_test_user, a_input, a_stdout, a_stderr, log_outpu
514513
except TypeError:
515514
print('Need list or tuple, got %s' % type(command))
516515
if use_test_user:
517-
command = ['runuser', options.username, '-c', ' '.join(map(__prepare_shell_argument, command))]
516+
command = ['runuser', options.username, '-c', ' '.join(map(shell_quote, command))]
518517

519518
# Figure out stdin
520519
stdin = None

0 commit comments

Comments
 (0)