Skip to content

Commit 24c2478

Browse files
committed
Fix escaping of special characters in INI writer
Values are now enclosed by double quotes while using the `to_json` filter for the escaping.
1 parent 2eeea8f commit 24c2478

File tree

3 files changed

+5
-7
lines changed

3 files changed

+5
-7
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bugfixes:
2+
- Fix escaping of special characters within the generic INI writer (:code:`icingaweb2` role). Values are now enclosed by double quotes while using the :code:`to_json` filter for the escaping (#426).

molecule/ini-configuration-tests/tests/integration/test_ini_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ def test_string(host):
22
i2_file = host.file("/tmp/string")
33
print(i2_file.content_string)
44
assert i2_file.is_file
5-
assert i2_file.content_string == "\n[section]\ntest = string\n"
5+
assert i2_file.content_string == '\n[section]\ntest = "string"\n'
66

77
def test_number(host):
88
i2_file = host.file("/tmp/number")

roles/icingaweb2/templates/ini_template.j2

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33

44
[{{ section }}]
55
{% for option, value in options.items() %}
6-
{% if value is number %}
7-
{{ option }} = "{{ value | quote }}"
8-
{% elif value is iterable and (value is not string and value is not mapping) %}
6+
{% if value is iterable and (value is not string and value is not mapping) %}
97
{{ option }} = "{{ value | join(', ') }}"
10-
{% elif ( value is string and ( "=" in value or "!" in value or " " in value ) )%}
11-
{{ option }} = "{{ value }}"
128
{% else %}
13-
{{ option }} = {{ value }}
9+
{{ option }} = "{{ value | to_json | trim('"') }}"
1410
{% endif %}
1511
{% endfor %}
1612
{% endfor %}

0 commit comments

Comments
 (0)