From 66200a5da56fb25f8dabd3722c1c69d56dd1cf37 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:28:37 +0200 Subject: [PATCH] [PR #8185/9307b76e backport][stable-8] fix: Ensuring interpolation is disabled for ConfigParser (#8210) fix: Ensuring interpolation is disabled for ConfigParser (#8185) * fix: Ensuring interpolation is disabled for ConfigParser This PR disables interpolation of ConfigParser and adds test coverage for that. * Adding changelog fragment * Fixing missing extension of changelog fragment * Adding issue link to changelog fragment * Update changelogs/fragments/8183-from_ini_to_ini.yml Co-authored-by: Felix Fontein --------- Co-authored-by: Felix Fontein (cherry picked from commit 9307b76e744661ef8d62bf829f02393100e8ba91) Co-authored-by: Steffen Scheib <37306894+sscheib@users.noreply.github.com> --- changelogs/fragments/8183-from_ini_to_ini.yml | 3 +++ plugins/filter/from_ini.py | 2 +- plugins/filter/to_ini.py | 2 +- .../integration/targets/filter_from_ini/tasks/main.yml | 10 ++++++++-- tests/integration/targets/filter_to_ini/tasks/main.yml | 6 ++++++ 5 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 changelogs/fragments/8183-from_ini_to_ini.yml diff --git a/changelogs/fragments/8183-from_ini_to_ini.yml b/changelogs/fragments/8183-from_ini_to_ini.yml new file mode 100644 index 0000000000..1ff455f6ee --- /dev/null +++ b/changelogs/fragments/8183-from_ini_to_ini.yml @@ -0,0 +1,3 @@ +bugfixes: + - "to_ini filter plugin - disabling interpolation of ``ConfigParser`` to allow converting values with a ``%`` sign (https://github.com/ansible-collections/community.general/issues/8183, https://github.com/ansible-collections/community.general/pull/8185)." + - "from_ini filter plugin - disabling interpolation of ``ConfigParser`` to allow converting values with a ``%`` sign (https://github.com/ansible-collections/community.general/issues/8183, https://github.com/ansible-collections/community.general/pull/8185)." diff --git a/plugins/filter/from_ini.py b/plugins/filter/from_ini.py index d68b51092e..6fe83875e6 100644 --- a/plugins/filter/from_ini.py +++ b/plugins/filter/from_ini.py @@ -57,7 +57,7 @@ class IniParser(ConfigParser): ''' Implements a configparser which is able to return a dict ''' def __init__(self): - super().__init__() + super().__init__(interpolation=None) self.optionxform = str def as_dict(self): diff --git a/plugins/filter/to_ini.py b/plugins/filter/to_ini.py index 22ef16d722..bdf2dde270 100644 --- a/plugins/filter/to_ini.py +++ b/plugins/filter/to_ini.py @@ -63,7 +63,7 @@ class IniParser(ConfigParser): ''' Implements a configparser which sets the correct optionxform ''' def __init__(self): - super().__init__() + super().__init__(interpolation=None) self.optionxform = str diff --git a/tests/integration/targets/filter_from_ini/tasks/main.yml b/tests/integration/targets/filter_from_ini/tasks/main.yml index a2eca36a6e..abb92dfc55 100644 --- a/tests/integration/targets/filter_from_ini/tasks/main.yml +++ b/tests/integration/targets/filter_from_ini/tasks/main.yml @@ -12,15 +12,21 @@ another_section: connection: 'ssh' + interpolate_test: + interpolate_test_key: '%' + - name: 'Write INI file that reflects ini_test_dict to {{ ini_test_file }}' ansible.builtin.copy: dest: '{{ ini_test_file }}' content: | [section_name] - key_name=key value + key_name = key value [another_section] - connection=ssh + connection = ssh + + [interpolate_test] + interpolate_test_key = % - name: 'Slurp the test file: {{ ini_test_file }}' ansible.builtin.slurp: diff --git a/tests/integration/targets/filter_to_ini/tasks/main.yml b/tests/integration/targets/filter_to_ini/tasks/main.yml index 877d4471d8..e16aa98a5a 100644 --- a/tests/integration/targets/filter_to_ini/tasks/main.yml +++ b/tests/integration/targets/filter_to_ini/tasks/main.yml @@ -16,6 +16,9 @@ another_section: connection: 'ssh' + interpolate_test: + interpolate_test_key: '%' + - name: 'Write INI file manually to {{ ini_test_file }}' ansible.builtin.copy: dest: '{{ ini_test_file }}' @@ -26,6 +29,9 @@ [another_section] connection = ssh + [interpolate_test] + interpolate_test_key = % + - name: 'Slurp the manually created test file: {{ ini_test_file }}' ansible.builtin.slurp: src: '{{ ini_test_file }}'