From 0a88c55194e8ac54eb937ef235112830eef22098 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Tue, 8 Sep 2020 11:53:06 +0200 Subject: [PATCH] quoted-strings: Fix detecting strings with hashtag as requiring quotes --- tests/rules/test_quoted_strings.py | 3 ++- yamllint/rules/quoted_strings.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/rules/test_quoted_strings.py b/tests/rules/test_quoted_strings.py index d66cb0b..1ee86a1 100644 --- a/tests/rules/test_quoted_strings.py +++ b/tests/rules/test_quoted_strings.py @@ -330,7 +330,8 @@ class QuotedTestCase(RuleTestCase): '- "%wheel ALL=(ALL) NOPASSWD: ALL"\n' '- \'"quoted"\'\n' '- "\'foo\' == \'bar\'"\n' - '- "\'Mac\' in ansible_facts.product_name"\n', + '- "\'Mac\' in ansible_facts.product_name"\n' + '- \'foo # bar\'\n', conf) self.check('---\n' 'k1: ""\n' diff --git a/yamllint/rules/quoted_strings.py b/yamllint/rules/quoted_strings.py index 78a2556..279cd6a 100644 --- a/yamllint/rules/quoted_strings.py +++ b/yamllint/rules/quoted_strings.py @@ -160,7 +160,7 @@ def _quotes_are_needed(string): try: a, b = loader.get_token(), loader.get_token() 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 True except yaml.scanner.ScannerError: