Skip to content

Commit

Permalink
yaml_preprocessor: fix processing empty sequences to null
Browse files Browse the repository at this point in the history
* Fix bug where preprocessing an empty list converts it to null
  • Loading branch information
pbelanger-avid committed Jan 19, 2023
1 parent 631168f commit 59097fa
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion flatland_server/src/yaml_preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void YamlPreprocessor::ProcessNodes(YAML::Node &node,
// copy the elements to a new sequence, checking for $[include] expressions
// as we go. If an include is found, replace it with one or more nodes
// parsed from the included file.
YAML::Node new_sequence;
YAML::Node new_sequence = YAML::Node(YAML::NodeType::Sequence);
for (YAML::Node child : node) {
std::vector<YAML::Node> included_nodes = {};
if (ProcessSequenceIncludeNode(included_nodes, child, ref_path)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ f:
- second element
- third element
- parent last element
g: []
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ f:
- parent first element
- $[include] include.sequence.yaml
- parent last element
g: [] # Test: make sure empty lists are not modified
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ TEST(YamlPreprocTest, testIncludeStrings) {
compareNodes("f", 2, in, out);
compareNodes("f", 3, in, out);
compareNodes("f", 4, in, out);

// previously we had a bug where empty lists would be converted to null
EXPECT_EQ(YAML::NodeType::Sequence, in["g"].Type());
EXPECT_EQ(0, in["g"].size());
}

// Run all the tests that were declared with TEST()
Expand Down

0 comments on commit 59097fa

Please sign in to comment.