quoted-strings: Fix detecting strings with hashtag as requiring quotes

This commit is contained in:
Julien Falque 2020-09-08 11:53:06 +02:00 committed by GitHub
parent ac19d1e427
commit 0a88c55194
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -330,7 +330,8 @@ class QuotedTestCase(RuleTestCase):
'- "%wheel ALL=(ALL) NOPASSWD: ALL"\n' '- "%wheel ALL=(ALL) NOPASSWD: ALL"\n'
'- \'"quoted"\'\n' '- \'"quoted"\'\n'
'- "\'foo\' == \'bar\'"\n' '- "\'foo\' == \'bar\'"\n'
'- "\'Mac\' in ansible_facts.product_name"\n', '- "\'Mac\' in ansible_facts.product_name"\n'
'- \'foo # bar\'\n',
conf) conf)
self.check('---\n' self.check('---\n'
'k1: ""\n' 'k1: ""\n'

View File

@ -160,7 +160,7 @@ def _quotes_are_needed(string):
try: try:
a, b = loader.get_token(), loader.get_token() a, b = loader.get_token(), loader.get_token()
if (isinstance(a, yaml.ScalarToken) and a.style is None and if (isinstance(a, yaml.ScalarToken) and a.style is None and
isinstance(b, yaml.BlockEndToken)): isinstance(b, yaml.BlockEndToken) and a.value == string):
return False return False
return True return True
except yaml.scanner.ScannerError: except yaml.scanner.ScannerError: