Skip to content

Commit

Permalink
Ensure variable syntax before matching in VariableHasSpacesRule (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
awcrosby authored Jun 7, 2019
1 parent e73fb6c commit 69f5e96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/ansiblelint/rules/VariableHasSpacesRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class VariableHasSpacesRule(AnsibleLintRule):
tags = ['formatting']
version_added = 'v4.0.0'

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

def match(self, file, line):
if not self.variable_syntax.search(line):
return
return self.bracket_regex.search(line)
4 changes: 4 additions & 0 deletions test/TestVariableHasSpaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
- name: bad variable format
debug:
msg: "{{bad_format }}"
- name: not a jinja variable
debug:
msg: "test"
example: "data = ${lookup{$local_part}lsearch{/etc/aliases}}"
'''


Expand Down

0 comments on commit 69f5e96

Please sign in to comment.