From 5da7301ec981f8887ddb1dd2a7447d5a566263d9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 3 Feb 2023 13:26:32 +0100 Subject: [PATCH] test-client: add Util.shlex_join() helper --- src/tests/client/test-client.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/tests/client/test-client.py b/src/tests/client/test-client.py index e936c4c452..66212501eb 100755 --- a/src/tests/client/test-client.py +++ b/src/tests/client/test-client.py @@ -251,7 +251,8 @@ class Util: ).search @staticmethod - def quote(s): + def shlex_quote(s): + # Reimplement shlex.quote(). if Util.python_has_version(3, 3): return shlex.quote(s) if not s: @@ -260,6 +261,11 @@ class Util: return s return "'" + s.replace("'", "'\"'\"'") + "'" + @staticmethod + def shlex_join(args): + # Reimplement shlex.join() + return " ".join(Util.shlex_quote(s) for s in args) + @staticmethod def popen_wait(p, timeout=0): (res, b_stdout, b_stderr) = Util.popen_wait_read( @@ -1024,7 +1030,7 @@ class TestNmcli(NmTestBase): self.assertEqual(returncode, -5) if check_on_disk: - cmd = "$NMCLI %s" % (" ".join([Util.quote(a) for a in args[1:]])) + cmd = "$NMCLI %s" % (Util.shlex_join(args[1:]),) cmd = Util.replace_text(cmd, replace_cmd) if returncode < 0: @@ -1971,16 +1977,13 @@ def main(): "eval `dbus-launch --sh-syntax`;\n" + 'trap "kill $DBUS_SESSION_BUS_PID" EXIT;\n' + "\n" - + " ".join( + + Util.shlex_join( [ - Util.quote(a) - for a in [ - sys.executable, - __file__, - "--started-with-dbus-session", - ] - + sys.argv[1:] + sys.executable, + __file__, + "--started-with-dbus-session", ] + + sys.argv[1:] ) + " \n" + "",