1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-03 14:52:21 +02:00

Don't escape / when rendering JSON.

/ is escaped in the spec but the Perl renderer we use does not escape it which leads to checksum mismatches between the two sets of code.

This particular escape seems to be a more recent addition to the spec and is targeted toward embedding JSON in JavaScript.

\/ is still allowed when parsing JSON.
This commit is contained in:
David Steele 2019-05-22 11:10:43 -04:00
parent 664054fea9
commit 3da60f4b5e
3 changed files with 9 additions and 13 deletions

View File

@ -677,10 +677,6 @@ jsonFromStrInternal(String *json, const String *string)
strCat(json, "\\\\");
break;
case '/':
strCat(json, "\\/");
break;
case '\n':
strCat(json, "\\n");
break;

View File

@ -137,7 +137,7 @@ testRun(void)
{
TEST_RESULT_STR(strPtr(jsonFromStr(NULL)), "null", "null string");
TEST_RESULT_STR(strPtr(jsonFromStr(strNew("simple string"))), "\"simple string\"", "simple string");
TEST_RESULT_STR(strPtr(jsonFromStr(strNew("\"\\/\b\n\r\t\f"))), "\"\\\"\\\\\\/\\b\\n\\r\\t\\f\"", "string escapes");
TEST_RESULT_STR(strPtr(jsonFromStr(strNew("\"\\/\b\n\r\t\f"))), "\"\\\"\\\\/\\b\\n\\r\\t\\f\"", "string escapes");
}
// *****************************************************************************************************************************
@ -254,7 +254,7 @@ testRun(void)
"{\"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\"}}",
"\"section\":{\"escape\":\"\\\"\\\\/\\b\\n\\r\\t\\f\",\"key1\":\"value1\",\"key2\":null,\"key3\":\"value2\"}}",
" sorted json string result, no pretty print");
TEST_ASSIGN(json, jsonFromVar(keyValue, 4), "KeyValue - indent 4");
@ -272,7 +272,7 @@ testRun(void)
" 1\n"
" ],\n"
" \"section\" : {\n"
" \"escape\" : \"\\\"\\\\\\/\\b\\n\\r\\t\\f\",\n"
" \"escape\" : \"\\\"\\\\/\\b\\n\\r\\t\\f\",\n"
" \"key1\" : \"value1\",\n"
" \"key2\" : null,\n"
" \"key3\" : \"value2\"\n"
@ -294,7 +294,7 @@ testRun(void)
"[{\"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\"}}]",
"\"section\":{\"escape\":\"\\\"\\\\/\\b\\n\\r\\t\\f\",\"key1\":\"value1\",\"key2\":null,\"key3\":\"value2\"}}]",
" sorted json string result no pretty print");
Variant *keyValue2 = varDup(keyValue);
@ -305,11 +305,11 @@ testRun(void)
"[{\"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\"}},"
"\"section\":{\"escape\":\"\\\"\\\\/\\b\\n\\r\\t\\f\",\"key1\":\"value1\",\"key2\":null,\"key3\":\"value2\"}},"
"{\"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\"}}]",
"\"section\":{\"escape\":\"\\\"\\\\/\\b\\n\\r\\t\\f\",\"key1\":\"value1\",\"key2\":null,\"key3\":\"value2\"}}]",
" sorted json string result no pretty print");
TEST_ASSIGN(json, jsonFromVar(varListOuter, 2), "VariantList - indent 2 - multiple elements");
@ -328,7 +328,7 @@ testRun(void)
" 1\n"
" ],\n"
" \"section\" : {\n"
" \"escape\" : \"\\\"\\\\\\/\\b\\n\\r\\t\\f\",\n"
" \"escape\" : \"\\\"\\\\/\\b\\n\\r\\t\\f\",\n"
" \"key1\" : \"value1\",\n"
" \"key2\" : null,\n"
" \"key3\" : \"value2\"\n"
@ -347,7 +347,7 @@ testRun(void)
" 1\n"
" ],\n"
" \"section\" : {\n"
" \"escape\" : \"\\\"\\\\\\/\\b\\n\\r\\t\\f\",\n"
" \"escape\" : \"\\\"\\\\/\\b\\n\\r\\t\\f\",\n"
" \"key1\" : \"value1\",\n"
" \"key2\" : null,\n"
" \"key3\" : \"value2\"\n"

View File

@ -67,7 +67,7 @@ testRun(void)
"\"config\":{\"negate\":true,\"reset\":false,\"source\":\"param\",\"valid\":true},"
"\"online\":{\"negate\":true,\"reset\":false,\"source\":\"param\",\"valid\":true,\"value\":false},"
"\"pg1-host\":{\"negate\":false,\"reset\":true,\"source\":\"default\",\"valid\":true},"
"\"pg1-path\":{\"negate\":false,\"reset\":false,\"source\":\"config\",\"valid\":true,\"value\":\"\\/path\\/db\\/pg\"},"
"\"pg1-path\":{\"negate\":false,\"reset\":false,\"source\":\"config\",\"valid\":true,\"value\":\"/path/db/pg\"},"
"\"protocol-timeout\":{\"negate\":false,\"reset\":false,\"source\":\"param\",\"valid\":true,\"value\":1.1},"
"\"repo1-cipher-pass\":{\"negate\":false,\"reset\":false,\"source\":\"config\",\"valid\":true,"
"\"value\":\"part1\\npart2\"},"