diff --git a/changelogs/fragments/11026-xfconf-empty-array.yml b/changelogs/fragments/11026-xfconf-empty-array.yml new file mode 100644 index 0000000000..f03b57126a --- /dev/null +++ b/changelogs/fragments/11026-xfconf-empty-array.yml @@ -0,0 +1,3 @@ +bugfixes: + - xfconf - fix handling of empty array properties (https://github.com/ansible-collections/community.general/pull/11026). + - xfconf_info - fix handling of empty array properties (https://github.com/ansible-collections/community.general/pull/11026). diff --git a/plugins/modules/xfconf.py b/plugins/modules/xfconf.py index 1c33e6ecdf..36da9cfaba 100644 --- a/plugins/modules/xfconf.py +++ b/plugins/modules/xfconf.py @@ -209,8 +209,11 @@ class XFConfProperty(StateModuleHelper): result = out.rstrip() if "Value is an array with" in result: result = result.split("\n") - result.pop(0) - result.pop(0) + if len(result) > 1: + result.pop(0) + result.pop(0) + else: + return [] return result diff --git a/plugins/modules/xfconf_info.py b/plugins/modules/xfconf_info.py index d4d6499dae..ecc1292f4b 100644 --- a/plugins/modules/xfconf_info.py +++ b/plugins/modules/xfconf_info.py @@ -149,9 +149,12 @@ class XFConfInfo(ModuleHelper): result = out.rstrip() if "Value is an array with" in result: result = result.split("\n") - result.pop(0) - result.pop(0) self.vars.is_array = True + if len(result) > 1: + result.pop(0) + result.pop(0) + else: + return [] return result diff --git a/tests/unit/plugins/modules/test_xfconf.yaml b/tests/unit/plugins/modules/test_xfconf.yaml index 0397108c1d..fed9db6d88 100644 --- a/tests/unit/plugins/modules/test_xfconf.yaml +++ b/tests/unit/plugins/modules/test_xfconf.yaml @@ -206,6 +206,55 @@ test_cases: rc: 0 out: '' err: '' + - id: test_property_array_previously_empty + input: + channel: xfwm4 + property: /general/workspace_names + state: present + value_type: string + value: [A, B, C] + output: + changed: true + previous_value: [] + type: [string, string, string] + value: [A, B, C] + version: 4.18.1 + mocks: + run_command: + - command: [/testbin/xfconf-query, --version] + environ: *env-def + rc: 0 + out: *version-output + err: '' + - command: [/testbin/xfconf-query, --channel, xfwm4, --property, /general/workspace_names] + environ: *env-def + rc: 0 + out: "Value is an array with 0 items:\n\n" + err: '' + - command: + - /testbin/xfconf-query + - --channel + - xfwm4 + - --property + - /general/workspace_names + - --create + - --force-array + - --type + - string + - --set + - A + - --type + - string + - --set + - B + - --type + - string + - --set + - C + environ: *env-def + rc: 0 + out: '' + err: '' - id: test_property_reset_value input: channel: xfwm4