-
Notifications
You must be signed in to change notification settings - Fork 3
Fix mergYAMLNodes when the node is a sequence #128
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -269,23 +269,34 @@ std::string extractFolderPath(const std::string& filePath) { | |||||||||||||||||||
|
||||||||||||||||||||
|
||||||||||||||||||||
void mergeYAMLNodes(YAML::Node& dest, const YAML::Node& src) { | ||||||||||||||||||||
if (!src || src.IsNull()) return; | ||||||||||||||||||||
|
||||||||||||||||||||
for (const auto& item : src) { | ||||||||||||||||||||
std::string key = item.first.as<std::string>(); | ||||||||||||||||||||
if (!dest[key]) { | ||||||||||||||||||||
// If the key doesn't exist in the destination node, simply add it | ||||||||||||||||||||
dest[key] = item.second; | ||||||||||||||||||||
} | ||||||||||||||||||||
else { | ||||||||||||||||||||
// If the key exists in the destination node, merge the values | ||||||||||||||||||||
// If both values are maps, recursively merge them | ||||||||||||||||||||
if (dest[key].IsMap() && item.second.IsMap()) { | ||||||||||||||||||||
mergeYAMLNodes(dest[key], item.second); | ||||||||||||||||||||
// If src is a map | ||||||||||||||||||||
if (src.IsMap()) { | ||||||||||||||||||||
for (const auto& item : src) { | ||||||||||||||||||||
const YAML::Node& keyNode = item.first; | ||||||||||||||||||||
const YAML::Node& srcValue = item.second; | ||||||||||||||||||||
const std::string key = keyNode.as<std::string>(); | ||||||||||||||||||||
|
||||||||||||||||||||
if (!dest[key]) { | ||||||||||||||||||||
dest[key] = srcValue; | ||||||||||||||||||||
} | ||||||||||||||||||||
else { | ||||||||||||||||||||
// Otherwise, overwrite the value in the destination node | ||||||||||||||||||||
dest[key] = item.second; | ||||||||||||||||||||
YAML::Node& destValue = dest[key]; | ||||||||||||||||||||
mergeYAMLNodes(destValue, srcValue); | ||||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
// If both are sequences, append src items to dest | ||||||||||||||||||||
else if (src.IsSequence() && dest.IsSequence()) { | ||||||||||||||||||||
for (const auto& item : src) { | ||||||||||||||||||||
dest.push_back(item); | ||||||||||||||||||||
} | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
// If dest and src are scalars or mismatched types, overwrite | ||||||||||||||||||||
else { | ||||||||||||||||||||
dest = src; | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
+298
to
+301
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Suggested change
|
||||||||||||||||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good that you're handling sequences. However, consider adding a check to ensure that the items being pushed back are compatible with the destination sequence's expected type. If they are not, this could lead to runtime errors or unexpected behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is too complex to do this check