Skip to content
Merged
Changes from 1 commit
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
57 changes: 56 additions & 1 deletion src/utils/yaml_node_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,62 @@
{
YAML::Emitter emitter;
emitter.SetIndent(2);
emitter << node;

// Helper function to handle nodes recursively
std::function<void(const YAML::Node&)> emit_node;
emit_node = [&emitter, &emit_node](const YAML::Node& n) {
switch (n.Type())
{
case YAML::NodeType::Map:
{
emitter << YAML::BeginMap;
for (const auto& kv : n)
{
emitter << YAML::Key;
emit_node(kv.first);
emitter << YAML::Value;
emit_node(kv.second);
}
emitter << YAML::EndMap;
break;
}
case YAML::NodeType::Sequence:
{
emitter << YAML::BeginSeq;
for (const auto& v : n)
{
emit_node(v);
}
emitter << YAML::EndSeq;
break;
}
default:
{
// Special handling for strings that look like octal numbers (e.g. "0755")
if (n.IsScalar())
{
std::string value = n.Scalar();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::string value = n.Scalar();
const std::string value = n.Scalar();

if (value.length() >= 2 && value[0] == '0' &&
std::all_of(value.begin() + 1, value.end(), ::isdigit))
{
emitter << YAML::LocalTag("str") << value;

Check warning on line 99 in src/utils/yaml_node_utils.cpp

View check run for this annotation

Codecov / codecov/patch

src/utils/yaml_node_utils.cpp#L99

Added line #L99 was not covered by tests
}
else
{
emitter << n;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else
{
emitter << n;
}

}
else
{
emitter << n;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
else
{
emitter << n;
}
emitter << n;

break;
}
}
};

emit_node(node);

if (!emitter.good())
throw std::runtime_error{fmt::format("Failed to emit YAML: {}", emitter.GetLastError())};

Expand Down
Loading