From 15cb2385d437795bb3efac29a95ca54131bb793b Mon Sep 17 00:00:00 2001 From: Jon Loeliger Date: Mon, 14 Jan 2019 13:32:16 -0600 Subject: [PATCH] JSON: Fix JSON formatting in the presence of namespaces. - Fix array_eval() to allow sequential nodes that do not have namepace nodes set as well as those that do. - Fix comma placement in an array list where it was being dropped between penultimate and last array elements. Signed-off-by: Jon Loeliger --- lib/src/clixon_json.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/src/clixon_json.c b/lib/src/clixon_json.c index f6f8ff23..785c47b4 100644 --- a/lib/src/clixon_json.c +++ b/lib/src/clixon_json.c @@ -189,16 +189,18 @@ array_eval(cxobj *xprev, if (xnext && xml_type(xnext)==CX_ELMNT && strcmp(xml_name(x),xml_name(xnext))==0){ - ns2 = xml_find_type_value(xnext, NULL, "xmlns", CX_ATTR); - if (nsx && ns2 && strcmp(nsx,ns2)==0) - eqnext++; + ns2 = xml_find_type_value(xnext, NULL, "xmlns", CX_ATTR); + if ((!nsx && !ns2) + || (nsx && ns2 && strcmp(nsx,ns2)==0)) + eqnext++; } if (xprev && xml_type(xprev)==CX_ELMNT && strcmp(xml_name(x),xml_name(xprev))==0){ - ns2 = xml_find_type_value(xprev, NULL, "xmlns", CX_ATTR); - if (nsx && ns2 && strcmp(nsx,ns2)==0) - eqprev++; + ns2 = xml_find_type_value(xprev, NULL, "xmlns", CX_ATTR); + if ((!nsx && !ns2) + || (nsx && ns2 && strcmp(nsx,ns2)==0)) + eqprev++; } if (eqprev && eqnext) array = MIDDLE_ARRAY; @@ -432,6 +434,8 @@ xml2json1_cbuf(cbuf *cb, break; } + int na = xml_child_nr_notype(x, CX_ATTR); + int commas = na - 1; for (i=0; i 0) { cprintf(cb, ",%s", pretty?"\n":""); + --commas; + } } switch (arraytype){ case BODY_ARRAY: