1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Bugfix: Fix parsing array values from osx_defaults (#358)

* Bugfix: Fix parsing array values in osx_defaults

Unquote values and unescape double quotes when reading array values from defaults.

* Fix fragments: fix_parsing_array_values_in_osx_defaults

Co-authored-by: Felix Fontein <felix@fontein.de>

* add test code for Bugfix: Fix parsing array values from osx_defaults

* handle spaces after the comma

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Kazufumi NOTO 2020-12-09 14:29:58 +09:00 committed by GitHub
parent e1bf23d27d
commit 1110e93c5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 2 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- osx_defaults - unquote values and unescape double quotes when reading array values (https://github.com/ansible-collections/community.general/pull/358).

View file

@ -237,8 +237,8 @@ class OSXDefaults(object):
value.pop(0)
value.pop(-1)
# Remove extra spaces and comma (,) at the end of values
value = [re.sub(',$', '', x.strip(' ')) for x in value]
# Remove spaces at beginning and comma (,) at the end, unquote and unescape double quotes
value = [re.sub('^ *"?|"?,? *$', '', x.replace('\\"', '"')) for x in value]
return value

View file

@ -208,3 +208,46 @@
- assert:
that: "{{ item.changed }}"
with_items: "{{ test_data_types.results }}"
- name: Ensure test key does not exist
osx_defaults:
domain: com.ansible.fake_array_value
key: ExampleArrayKey
state: absent
- name: add array value for the first time
osx_defaults:
domain: com.ansible.fake_array_value
key: ExampleArrayKey
value:
- 'Value with spaces'
type: array
array_add: yes
register: test_array_add
- assert:
that: test_array_add.changed
- name: add for the second time, should be skipped
osx_defaults:
domain: com.ansible.fake_array_value
key: ExampleArrayKey
value:
- 'Value with spaces'
type: array
array_add: yes
register: test_array_add
- assert:
that: not test_array_add.changed
- name: Clean up test key
osx_defaults:
domain: com.ansible.fake_array_value
key: ExampleArrayKey
state: absent
register: test_array_add
- assert:
that: test_array_add.changed