Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better logic for empty yaml files #3574

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, {})
Loading