Skip to content

Commit

Permalink
Allow Jinja2 whitespace control chars in vars (#500)
Browse files Browse the repository at this point in the history
* Allow Jinja2 whitespace control chars in vars
* Fix typo in VariableHasSpaces unit test
* Add test for jinja whitespace control
* Add additional test, use raw-string for regex
  • Loading branch information
netzvieh authored and awcrosby committed Apr 3, 2019
1 parent 9fedf0b commit 4f863c9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/ansiblelint/rules/VariableHasSpacesRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class VariableHasSpacesRule(AnsibleLintRule):
tags = ['formatting']
version_added = 'v4.0.0'

bracket_regex = re.compile("{{[^{' ]|[^ '}]}}")
bracket_regex = re.compile(r"{{[^{' -]|[^ '}-]}}")

def match(self, file, line):
return self.bracket_regex.search(line)
10 changes: 8 additions & 2 deletions test/TestVariableHasSpaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@
- name: good variable format
debug:
msg: "Value: {{ good_format }}"
- name: jijna escaping allowed
- name: jinja escaping allowed
debug:
msg: "{{ '{{' }}"
- name: jijna escaping allowed
- name: jinja escaping allowed
shell: docker info --format '{{ '{{' }}json .Swarm.LocalNodeState{{ '}}' }}' | tr -d '"'
- name: jinja whitespace control allowed
debug:
msg: |
{{ good_format }}/
{{- good_format }}
{{- good_format -}}
- name: bad variable format
debug:
msg: "{{bad_format}}"
Expand Down

0 comments on commit 4f863c9

Please sign in to comment.