Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/426-quotes-and-escaping-ini-writer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- 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).
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ def test_string(host):
i2_file = host.file("/tmp/string")
print(i2_file.content_string)
assert i2_file.is_file
assert i2_file.content_string == "\n[section]\ntest = string\n"
assert i2_file.content_string == '\n[section]\ntest = "string"\n'

def test_number(host):
i2_file = host.file("/tmp/number")
Expand Down
8 changes: 2 additions & 6 deletions roles/icingaweb2/templates/ini_template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@

[{{ section }}]
{% for option, value in options.items() %}
{% if value is number %}
{{ option }} = "{{ value | quote }}"
{% elif value is iterable and (value is not string and value is not mapping) %}
{% if value is iterable and (value is not string and value is not mapping) %}
{{ option }} = "{{ value | join(', ') }}"
{% elif ( value is string and ( "=" in value or "!" in value or " " in value ) )%}
{{ option }} = "{{ value }}"
{% else %}
{{ option }} = {{ value }}
{{ option }} = "{{ value | to_json | trim('"') }}"
{% endif %}
{% endfor %}
{% endfor %}
Expand Down