pgbackrest.git / summary / log / commit / refs

commit    aca11b2fa19337f934fc095e33f014d5e6df71f3
Author:   David Steele <david@pgmasters.net>
Date:     Tue Jun 04 21:40:27 2019 +0000

    Add String to types supported by JSON list render.
    
    All types should be supported eventually but for now this answers the need.


src/common/type/json.c | 15 +++++++++++---- test/src/module/common/typeJsonTest.c | 6 ++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/common/type/json.c b/src/common/type/json.c index 36497c044..f4edc30be 100644 --- a/src/common/type/json.c +++ b/src/common/type/json.c @@ -942,16 +942,23 @@ jsonFromVar(const Variant *var, unsigned int indent) // Add the indent formatting strCatFmt(jsonStr, "[%s", strPtr(indentDepth)); - // Currently only KeyValue list is supported + // Currently only KeyValue and String lists are supported for (unsigned int vlIdx = 0; vlIdx < varLstSize(vl); vlIdx++) { // If going to add another key, append a comma and format for the next line if (vlIdx > 0) strCatFmt(jsonStr, ",%s", strPtr(indentDepth)); - // Update the depth before processing the contents of the list element - strCat(indentDepth, strPtr(indentSpace)); - strCat(jsonStr, strPtr(jsonFromKvInternal(varKv(varLstGet(vl, vlIdx)), indentSpace, indentDepth))); + Variant *varSub = varLstGet(vl, vlIdx); + + if (varType(varSub) == varTypeKeyValue) + { + // Update the depth before processing the contents of the list element + strCat(indentDepth, strPtr(indentSpace)); + strCat(jsonStr, strPtr(jsonFromKvInternal(varKv(varSub), indentSpace, indentDepth))); + } + else + jsonFromStrInternal(jsonStr, varStr(varSub)); } // Decrease the depth diff --git a/test/src/module/common/typeJsonTest.c b/test/src/module/common/typeJsonTest.c index 674c16e22..8243d3092 100644 --- a/test/src/module/common/typeJsonTest.c +++ b/test/src/module/common/typeJsonTest.c @@ -287,11 +287,12 @@ testRun(void) TEST_RESULT_STR(strPtr(json), "[]", " empty list no pretty print"); TEST_ASSIGN(varListOuter, varNewVarLst(varLstNew()), "new variant list with keyValues"); + varLstAdd(varVarLst(varListOuter), varNewStrZ("ASTRING")); varLstAdd(varVarLst(varListOuter), keyValue); TEST_ASSIGN(json, jsonFromVar(varListOuter, 0), "VariantList - no indent"); TEST_RESULT_STR(strPtr(json), - "[{\"backup-info-size-delta\":1982702,\"backup-prior\":\"20161219-212741F_20161219-212803I\"," + "[\"ASTRING\",{\"backup-info-size-delta\":1982702,\"backup-prior\":\"20161219-212741F_20161219-212803I\"," "\"backup-reference\":[\"20161219-212741F\",\"20161219-212741F_20161219-212803I\",null]," "\"backup-timestamp-start\":1482182951,\"checksum-page-error\":[1]," "\"section\":{\"escape\":\"\\\"\\\\/\\b\\n\\r\\t\\f\",\"key1\":\"value1\",\"key2\":null,\"key3\":\"value2\"}}]", @@ -302,7 +303,7 @@ testRun(void) TEST_ASSIGN(json, jsonFromVar(varListOuter, 0), "VariantList - no indent - multiple elements"); TEST_RESULT_STR(strPtr(json), - "[{\"backup-info-size-delta\":1982702,\"backup-prior\":\"20161219-212741F_20161219-212803I\"," + "[\"ASTRING\",{\"backup-info-size-delta\":1982702,\"backup-prior\":\"20161219-212741F_20161219-212803I\"," "\"backup-reference\":[\"20161219-212741F\",\"20161219-212741F_20161219-212803I\",null]," "\"backup-timestamp-start\":1482182951,\"checksum-page-error\":[1]," "\"section\":{\"escape\":\"\\\"\\\\/\\b\\n\\r\\t\\f\",\"key1\":\"value1\",\"key2\":null,\"key3\":\"value2\"}}," @@ -315,6 +316,7 @@ testRun(void) TEST_ASSIGN(json, jsonFromVar(varListOuter, 2), "VariantList - indent 2 - multiple elements"); TEST_RESULT_STR(strPtr(json), "[\n" + " \"ASTRING\",\n" " {\n" " \"backup-info-size-delta\" : 1982702,\n" " \"backup-prior\" : \"20161219-212741F_20161219-212803I\",\n" [parent: 0ab6f3bb8700]