forked from external/yambar
yaml: keep original value when anchor and target node both defines the same key
When merging an anchor into a target yaml node, and both the target node and the anchor defines the same key(s), keep the value from the target node. Closes #286
This commit is contained in:
parent
5e3859f218
commit
971361b046
2 changed files with 19 additions and 10 deletions
26
yml.c
26
yml.c
|
@ -237,12 +237,15 @@ post_process(struct yml_node *node, char **error)
|
|||
.key = vv_it->item.key,
|
||||
.value = vv_it->item.value,
|
||||
};
|
||||
/* TODO: handle this. Is it an error? Or
|
||||
* should we replace the existing key/value
|
||||
* pair */
|
||||
assert(!dict_has_key(node, vv_it->item.key));
|
||||
|
||||
tll_push_back(node->dict.pairs, p);
|
||||
if (dict_has_key(node, vv_it->item.key)) {
|
||||
/* Prefer value in target dictionary, over the
|
||||
* value from the anchor */
|
||||
yml_destroy(vv_it->item.key);
|
||||
yml_destroy(vv_it->item.value);
|
||||
} else {
|
||||
tll_push_back(node->dict.pairs, p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Destroy list, but don't free (since its nodes
|
||||
|
@ -274,11 +277,14 @@ post_process(struct yml_node *node, char **error)
|
|||
.value = v_it->item.value,
|
||||
};
|
||||
|
||||
/* TODO: handle this. Is it an error? Or should we
|
||||
* replace the existing key/value pair */
|
||||
assert(!dict_has_key(node, v_it->item.key));
|
||||
|
||||
tll_push_back(node->dict.pairs, p);
|
||||
if (dict_has_key(node, v_it->item.key)) {
|
||||
/* Prefer value in target dictionary, over the
|
||||
* value from the anchor */
|
||||
yml_destroy(v_it->item.key);
|
||||
yml_destroy(v_it->item.value);
|
||||
} else {
|
||||
tll_push_back(node->dict.pairs, p);
|
||||
}
|
||||
}
|
||||
|
||||
/* Destroy list here, *without* freeing nodes (since
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue