Skip to content

Commit

Permalink
Better logic for empty yaml files
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Aug 6, 2024
1 parent de871c3 commit 16d1feb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cfnlint/decode/cfn_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions test/unit/module/decode/test_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, {})

0 comments on commit 16d1feb

Please sign in to comment.