From 3bda80918d5f00390ff958a3bfe1233243843d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Jeanneret?= Date: Thu, 9 Apr 2020 13:47:39 +0200 Subject: [PATCH] Ensure we don't pass empty params When using automated generation for some of the params we get an empty line entry at some point, leading to an empty parameter being added to the command. The unit-test was updated accordingly in order to avoid regressions. Change-Id: I82c9e68bea1a206c001f71873c213c0242380345 --- plugins/filter/shell_args.py | 11 ++++++----- tests/plugins/filter/test_shell_args.py | 6 ++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/filter/shell_args.py b/plugins/filter/shell_args.py index d0dd391..4c063bd 100644 --- a/plugins/filter/shell_args.py +++ b/plugins/filter/shell_args.py @@ -34,9 +34,10 @@ class FilterModule(object): arg = [arg] return_value = [] for a in arg: - val = quote(a) - if parameter: - return_value.append("{} {}".format(parameter, val)) - else: - return_value.append(val) + if a: + val = quote(a) + if parameter: + return_value.append("{} {}".format(parameter, val)) + else: + return_value.append(val) return ' '.join(return_value) diff --git a/tests/plugins/filter/test_shell_args.py b/tests/plugins/filter/test_shell_args.py index bc141ce..2b7fb61 100644 --- a/tests/plugins/filter/test_shell_args.py +++ b/tests/plugins/filter/test_shell_args.py @@ -53,3 +53,9 @@ class TestShellArgsFilters(tests_base.TestCase): expected = "'a b'" self.assertEqual(expected, self.filter.shell_arg_list(arg)) + + def test_shell_arg_list_avoid_none_in_list(self): + arg = ['a', None] + expected = '-p a' + self.assertEqual(expected, + self.filter.shell_arg_list(arg, parameter='-p'))