Fix empty files included by !include_dir_named (#108489)

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
pull/108508/head
Erik Montnemery 2024-01-20 15:12:32 +01:00 committed by GitHub
parent a3619e544e
commit 1cb5bbf865
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View File

@ -359,7 +359,12 @@ def _include_dir_named_yaml(loader: LoaderType, node: yaml.nodes.Node) -> NodeDi
filename = os.path.splitext(os.path.basename(fname))[0]
if os.path.basename(fname) == SECRET_YAML:
continue
mapping[filename] = load_yaml(fname, loader.secrets)
loaded_yaml = load_yaml(fname, loader.secrets)
if loaded_yaml is None:
# Special case, an empty file included by !include_dir_named is treated
# as an empty dictionary
loaded_yaml = NodeDictClass()
mapping[filename] = loaded_yaml
return _add_reference(mapping, loader, node)

View File

@ -193,7 +193,7 @@ def test_include_dir_list_recursive(
),
(
{"/test/first.yaml": "1", "/test/second.yaml": None},
{"first": 1, "second": None},
{"first": 1, "second": {}},
),
],
)