Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/main/cpp/jsonlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,21 @@ void JSONLayout::appendItem(const LogString& input, LogString& buf)
{
auto lastCodePoint = nextCodePoint;
auto ch = Transcoder::decode(input, nextCodePoint);
bool escapeReplacement = false;
if (nextCodePoint == lastCodePoint) // failed to decode input?
{
nextCodePoint = input.end();
ch = 0xFFFD; // The Unicode replacement character
escapeReplacement = true;
}
else if ((0xD800 <= ch && ch <= 0xDFFF) || 0x10FFFF < ch)
{
ch = 0xFFFD; // The Unicode replacement character
escapeReplacement = true;
}
else if (0x22 == ch || 0x5c == ch) // double quote or backslash?
;
else if (0x20 <= ch) // not a control character?
else if (!escapeReplacement && 0x20 <= ch) // not a control character?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change does nothing as escapeReplacement is always false in this conditional expression.

continue;

if (start != lastCodePoint)
Expand Down
16 changes: 15 additions & 1 deletion src/test/cpp/jsonlayouttest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ LOGUNIT_CLASS(JSONLayoutTest), public JSONLayout
LOGUNIT_TEST(testFormatWithPrettyPrint);
LOGUNIT_TEST(testGetSetLocationInfo);
LOGUNIT_TEST(testAppendQuotedEscapedString);
LOGUNIT_TEST(testAppendQuotedEscapedStringWithInvalidUtf8);
LOGUNIT_TEST_SUITE_END();


Expand Down Expand Up @@ -520,8 +521,21 @@ LOGUNIT_CLASS(JSONLayoutTest), public JSONLayout
appendQuotedEscapedString(escapedQuoted0xD822Name, problemNameLS);
LOGUNIT_ASSERT_EQUAL(expectedQuotedEscapedName, escapedQuoted0xD822Name);
}

void testAppendQuotedEscapedStringWithInvalidUtf8()
{
#if LOG4CXX_LOGCHAR_IS_UTF8
LogString malformed;
malformed.push_back('A');
malformed.push_back(static_cast<logchar>(0xC3));
malformed.push_back('B');

LogString escaped;
appendQuotedEscapedString(escaped, malformed);
LOGUNIT_ASSERT_EQUAL(LOG4CXX_STR("\"A\\ufffd\""), escaped);
#endif
}
};


LOGUNIT_TEST_SUITE_REGISTRATION(JSONLayoutTest);

Loading