Skip to content

Commit b28ac65

Browse files
authored
xfconf: fix existing empty array case (#11026)
* xfconf: fix existing empty array case * fix xfconf_info as well * add changelog frag
1 parent 9a7a316 commit b28ac65

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bugfixes:
2+
- xfconf - fix handling of empty array properties (https://github.com/ansible-collections/community.general/pull/11026).
3+
- xfconf_info - fix handling of empty array properties (https://github.com/ansible-collections/community.general/pull/11026).

plugins/modules/xfconf.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,11 @@ def process_command_output(self, rc, out, err):
209209
result = out.rstrip()
210210
if "Value is an array with" in result:
211211
result = result.split("\n")
212-
result.pop(0)
213-
result.pop(0)
212+
if len(result) > 1:
213+
result.pop(0)
214+
result.pop(0)
215+
else:
216+
return []
214217

215218
return result
216219

plugins/modules/xfconf_info.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ def process_command_output(self, rc, out, err):
149149
result = out.rstrip()
150150
if "Value is an array with" in result:
151151
result = result.split("\n")
152-
result.pop(0)
153-
result.pop(0)
154152
self.vars.is_array = True
153+
if len(result) > 1:
154+
result.pop(0)
155+
result.pop(0)
156+
else:
157+
return []
155158

156159
return result
157160

tests/unit/plugins/modules/test_xfconf.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,55 @@ test_cases:
206206
rc: 0
207207
out: ''
208208
err: ''
209+
- id: test_property_array_previously_empty
210+
input:
211+
channel: xfwm4
212+
property: /general/workspace_names
213+
state: present
214+
value_type: string
215+
value: [A, B, C]
216+
output:
217+
changed: true
218+
previous_value: []
219+
type: [string, string, string]
220+
value: [A, B, C]
221+
version: 4.18.1
222+
mocks:
223+
run_command:
224+
- command: [/testbin/xfconf-query, --version]
225+
environ: *env-def
226+
rc: 0
227+
out: *version-output
228+
err: ''
229+
- command: [/testbin/xfconf-query, --channel, xfwm4, --property, /general/workspace_names]
230+
environ: *env-def
231+
rc: 0
232+
out: "Value is an array with 0 items:\n\n"
233+
err: ''
234+
- command:
235+
- /testbin/xfconf-query
236+
- --channel
237+
- xfwm4
238+
- --property
239+
- /general/workspace_names
240+
- --create
241+
- --force-array
242+
- --type
243+
- string
244+
- --set
245+
- A
246+
- --type
247+
- string
248+
- --set
249+
- B
250+
- --type
251+
- string
252+
- --set
253+
- C
254+
environ: *env-def
255+
rc: 0
256+
out: ''
257+
err: ''
209258
- id: test_property_reset_value
210259
input:
211260
channel: xfwm4

0 commit comments

Comments
 (0)