mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-18 04:58:51 +02:00
Allow empty arrays in JSON parser.
This commit is contained in:
parent
8304d452b3
commit
2b02d37602
@ -37,6 +37,10 @@
|
||||
<p>Improve accuracy of <code>strSizeFormat()</code>.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Allow empty arrays in JSON parser.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Null-terminate list returned by <code>strLstPtr()</code>.</p>
|
||||
</release-item>
|
||||
|
@ -181,6 +181,13 @@ jsonToKv(const String *json)
|
||||
Variant *valueList = varNewVarLst(varLstNew());
|
||||
kvAdd(result, varNewStr(key), valueList);
|
||||
|
||||
// Continue if empty array
|
||||
if (jsonC[jsonPos + 1] == ']')
|
||||
{
|
||||
jsonPos += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
// ??? Currently only working with same-type simple single-dimensional arrays
|
||||
unsigned char arrayType = '\0';
|
||||
|
||||
|
@ -31,7 +31,6 @@ testRun(void)
|
||||
TEST_ERROR(jsonToKv(strNew("{\"key1\":[\"\",1]}")), JsonFormatError, "number found in array of type 's'");
|
||||
TEST_ERROR(jsonToKv(strNew("{\"key1\":[1,\"\"]}")), JsonFormatError, "string found in array of type 'n'");
|
||||
TEST_ERROR(jsonToKv(strNew("{\"key1\":[1}")), JsonFormatError, "expected array delimeter ']' but found '}'");
|
||||
TEST_ERROR(jsonToKv(strNew("{\"key1\":[]}")), JsonFormatError, "unknown array value type");
|
||||
TEST_ERROR(jsonToKv(strNew("{}")), JsonFormatError, "expected '\"' but found '}'");
|
||||
TEST_ERROR(jsonToKv(strNew("{\"key1\":nu")), JsonFormatError, "expected null delimit but found 'u'");
|
||||
TEST_ERROR(jsonToKv(strNew("{\"key1\":nul")), JsonFormatError, "null delimit not found");
|
||||
@ -86,6 +85,7 @@ testRun(void)
|
||||
strNew(
|
||||
"{\"backup-info-size-delta\":1982702,\"backup-prior\":\"20161219-212741F_20161219-212803I\","
|
||||
"\"backup-reference\":[\"20161219-212741F\",\"20161219-212741F_20161219-212803I\"],"
|
||||
"\"empty-array\":[],"
|
||||
"\"null-value\":null,\"checksum-page-error\":[1],\"backup-timestamp-start\":1482182951}")),
|
||||
"multpile values with array and null");
|
||||
TEST_RESULT_UINT(varUInt64(kvGet(kv, varNewStr(strNew("backup-info-size-delta")))), 1982702, " check integer");
|
||||
@ -95,6 +95,7 @@ testRun(void)
|
||||
"20161219-212741F", " check string array[0]");
|
||||
TEST_RESULT_STR(strPtr(varStr(varLstGet(varVarLst(kvGet(kv, varNewStr(strNew("backup-reference")))), 1))),
|
||||
"20161219-212741F_20161219-212803I", " check string array[1]");
|
||||
TEST_RESULT_UINT(varLstSize(varVarLst(kvGet(kv, varNewStr(strNew("empty-array"))))), 0, " check empty array");
|
||||
TEST_RESULT_PTR(varStr(kvGet(kv, varNewStr(strNew("null-value")))), NULL, " check null");
|
||||
TEST_RESULT_UINT(varUInt64(varLstGet(varVarLst(kvGet(kv, varNewStr(strNew("checksum-page-error")))), 0)), 1,
|
||||
" check integer array[0]");
|
||||
|
Loading…
x
Reference in New Issue
Block a user