From 16d1feb5915451a23494307e0656182b05803189 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Tue, 6 Aug 2024 08:37:52 -0700 Subject: [PATCH] Better logic for empty yaml files --- src/cfnlint/decode/cfn_yaml.py | 3 ++- test/unit/module/decode/test_decode.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cfnlint/decode/cfn_yaml.py b/src/cfnlint/decode/cfn_yaml.py index db9dd6e2a8..135a02291a 100644 --- a/src/cfnlint/decode/cfn_yaml.py +++ b/src/cfnlint/decode/cfn_yaml.py @@ -17,6 +17,7 @@ from yaml.resolver import Resolver from yaml.scanner import Scanner +from cfnlint.decode.mark import Mark from cfnlint.decode.node import dict_node, list_node, str_node from cfnlint.rules import Match from cfnlint.rules.errors import ParseError @@ -291,7 +292,7 @@ def loads(yaml_string, fname=None): template = loader.get_single_data() # Convert an empty file to an empty dict if template is None: - template = {} + template = dict_node({}, Mark(0, 0), Mark(0, 0)) return template diff --git a/test/unit/module/decode/test_decode.py b/test/unit/module/decode/test_decode.py index 296594d501..c00d647503 100644 --- a/test/unit/module/decode/test_decode.py +++ b/test/unit/module/decode/test_decode.py @@ -138,3 +138,7 @@ def test_decode_yaml_null_key(self): """ ) self.assertEqual(str(e.exception), err_msg) + + def test_decode_yaml_empty(self): + template = cfnlint.decode.cfn_yaml.loads("") + self.assertEqual(template, {})