Skip to content
Permalink
Browse files

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.
  • Loading branch information...
dwsteele committed May 22, 2019
1 parent 664054f commit 3da60f4b5ee8ed663fc5e8d8968709dbaadee1f6
Showing with 9 additions and 13 deletions.
  1. +0 −4 src/common/type/json.c
  2. +8 −8 test/src/module/common/typeJsonTest.c
  3. +1 −1 test/src/module/perl/configTest.c
@@ -677,10 +677,6 @@ jsonFromStrInternal(String *json, const String *string)
strCat(json, "\\\\");
break;

case '/':
strCat(json, "\\/");
break;

case '\n':
strCat(json, "\\n");
break;
@@ -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"
@@ -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\"},"

0 comments on commit 3da60f4

Please sign in to comment.
You can’t perform that action at this time.