printers CHANGE try to print all values
Even unresolved unions. The printed value
will be wrong only in extremely rare cases.
Fixes sysrepo/sysrepo#1069
diff --git a/src/printer_json.c b/src/printer_json.c
index 4b13918..5b726a2 100644
--- a/src/printer_json.c
+++ b/src/printer_json.c
@@ -173,6 +173,7 @@
case LY_TYPE_INST:
case LY_TYPE_INT64:
case LY_TYPE_UINT64:
+ case LY_TYPE_UNION:
case LY_TYPE_DEC64:
json_print_string(out, leaf->value_str);
break;
diff --git a/src/printer_xml.c b/src/printer_xml.c
index d99e412..10933fd 100644
--- a/src/printer_xml.c
+++ b/src/printer_xml.c
@@ -269,6 +269,7 @@
LY_DATA_TYPE datatype;
char *p;
size_t len;
+ enum int_log_opts prev_ilo;
if (toplevel || !node->parent || nscmp(node, node->parent)) {
/* print "namespace" */
@@ -290,26 +291,26 @@
printvalue:
switch (datatype) {
case LY_TYPE_STRING:
+ ly_ilo_change(NULL, ILO_IGNORE, &prev_ilo, NULL);
type = lyd_leaf_type((struct lyd_node_leaf_list *)leaf);
- if (!type) {
- /* error */
- ly_print(out, "\"(!error!)\"");
- return EXIT_FAILURE;
- }
- for (tpdf = type->der;
- tpdf->module && (strcmp(tpdf->name, "xpath1.0") || strcmp(tpdf->module->name, "ietf-yang-types"));
- tpdf = tpdf->type.der);
- /* special handling of ietf-yang-types xpath1.0 */
- if (tpdf->module) {
- /* avoid code duplication - use instance-identifier printer which gets necessary namespaces to print */
- datatype = LY_TYPE_INST;
- goto printvalue;
+ ly_ilo_restore(NULL, prev_ilo, NULL, 0);
+ if (type) {
+ for (tpdf = type->der;
+ tpdf->module && (strcmp(tpdf->name, "xpath1.0") || strcmp(tpdf->module->name, "ietf-yang-types"));
+ tpdf = tpdf->type.der);
+ /* special handling of ietf-yang-types xpath1.0 */
+ if (tpdf->module) {
+ /* avoid code duplication - use instance-identifier printer which gets necessary namespaces to print */
+ datatype = LY_TYPE_INST;
+ goto printvalue;
+ }
}
/* fallthrough */
case LY_TYPE_BINARY:
case LY_TYPE_BITS:
case LY_TYPE_ENUM:
case LY_TYPE_BOOL:
+ case LY_TYPE_UNION:
case LY_TYPE_DEC64:
case LY_TYPE_INT8:
case LY_TYPE_INT16: