diff --git a/src/common/type/json.c b/src/common/type/json.c index 077d7bf2c..623c9ba56 100644 --- a/src/common/type/json.c +++ b/src/common/type/json.c @@ -254,7 +254,7 @@ jsonToStrInternal(const char *json, unsigned int *jsonPos) noEscapeSize = 0; } - (*jsonPos)++;; + (*jsonPos)++; switch (json[*jsonPos]) { @@ -290,6 +290,22 @@ jsonToStrInternal(const char *json, unsigned int *jsonPos) strCatChr(result, '\f'); break; + case 'u': + { + (*jsonPos)++; + + // We don't know how to decode anything except ASCII so fail if it looks like Unicode + if (strncmp(json + *jsonPos, "00", 2) != 0) + THROW_FMT(JsonFormatError, "unable to decode '%.4s'", json + *jsonPos); + + // Decode char + (*jsonPos) += 2; + strCatChr(result, (char)cvtZToUIntBase(strZ(strNewN(json + *jsonPos, 2)), 16)); + (*jsonPos) += 1; + + break; + } + default: THROW_FMT(JsonFormatError, "invalid escape character '%c'", json[*jsonPos]); } diff --git a/test/src/module/common/typeJsonTest.c b/test/src/module/common/typeJsonTest.c index 3945d1712..4e964d187 100644 --- a/test/src/module/common/typeJsonTest.c +++ b/test/src/module/common/typeJsonTest.c @@ -36,6 +36,7 @@ testRun(void) if (testBegin("jsonToStr() and jsonToStrInternal()")) { TEST_ERROR(jsonToStr(strNew("\"\\j\"")), JsonFormatError, "invalid escape character 'j'"); + TEST_ERROR(jsonToStr(strNew("\"\\uffff\"")), JsonFormatError, "unable to decode 'ffff'"); TEST_ERROR(jsonToStr(strNew("\"runonstring")), JsonFormatError, "expected '\"' but found null delimiter"); TEST_ERROR(jsonToStr(strNew("\"normal\"L")), JsonFormatError, "unexpected characters after string at 'L'"); TEST_ERROR(jsonToStr(strNew("nullz")), JsonFormatError, "unexpected characters after string at 'z'"); @@ -43,7 +44,7 @@ testRun(void) TEST_RESULT_STR(jsonToStr(strNew("null")), NULL, "null string"); TEST_RESULT_STR_Z(jsonToStr(strNew(" \"test\"")), "test", "simple string"); TEST_RESULT_STR_Z(jsonToStr(strNew("\"te\\\"st\" ")), "te\"st", "string with quote"); - TEST_RESULT_STR_Z(jsonToStr(strNew("\"\\\"\\\\\\/\\b\\n\\r\\t\\f\"")), "\"\\/\b\n\r\t\f", "string with escapes"); + TEST_RESULT_STR_Z(jsonToStr(strNew("\"\\\"\\\\\\/\\b\\n\\r\\t\\f\\u0026\"")), "\"\\/\b\n\r\t\f&", "string with escapes"); } // *****************************************************************************************************************************