This is an automated email from the ASF dual-hosted git repository.

swebb2066 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4cxx.git


The following commit(s) were added to refs/heads/master by this push:
     new e73ecd02 Normalize invalid Unicode scalar values in JSONLayout output 
(#678)
e73ecd02 is described below

commit e73ecd027be58dff249eb194276e99a89e27be5e
Author: jmestwa-coder <[email protected]>
AuthorDate: Mon May 18 08:23:15 2026 +0530

    Normalize invalid Unicode scalar values in JSONLayout output (#678)
---
 src/main/cpp/jsonlayout.cpp     |  4 ++++
 src/test/cpp/jsonlayouttest.cpp | 10 +++-------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/main/cpp/jsonlayout.cpp b/src/main/cpp/jsonlayout.cpp
index b7da35c5..76e9b9d8 100644
--- a/src/main/cpp/jsonlayout.cpp
+++ b/src/main/cpp/jsonlayout.cpp
@@ -228,6 +228,10 @@ void JSONLayout::appendItem(const LogString& input, 
LogString& buf)
                        nextCodePoint = input.end();
                        ch = 0xFFFD; // The Unicode replacement character
                }
+               else if ((0xD800 <= ch && ch <= 0xDFFF) || 0x10FFFF < ch)
+               {
+                       ch = 0xFFFD; // The Unicode replacement character
+               }
                else if (0x22 == ch || 0x5c == ch) // double quote or backslash?
                        ;
                else if (0x20 <= ch) // not a control character?
diff --git a/src/test/cpp/jsonlayouttest.cpp b/src/test/cpp/jsonlayouttest.cpp
index b375554b..f6b175a2 100644
--- a/src/test/cpp/jsonlayouttest.cpp
+++ b/src/test/cpp/jsonlayouttest.cpp
@@ -510,15 +510,11 @@ public:
                LOGUNIT_ASSERT_EQUAL(expectedQuotedEscapedName, 
quotedEscapedName);
 
                Transcoder::encode(0xD822, problemNameLS); // Add a character 
that cannot be converted to UTF16
-#if LOG4CXX_LOGCHAR_IS_WCHAR && defined(__STDC_ISO_10646__)
-               expectedQuotedEscapedName[expectedQuotedEscapedName.size() - 1] 
= 0xD822;
-               expectedQuotedEscapedName += 0x22; // Add a double quote at the 
end
-#elif LOG4CXX_LOGCHAR_IS_WCHAR
+#if LOG4CXX_LOGCHAR_IS_WCHAR && !defined(__STDC_ISO_10646__)
                // encodeUTF16 adds 0xD822, but decodeUTF16 cannot convert 
0xD822
                
expectedQuotedEscapedName.insert(expectedQuotedEscapedName.size() - 1, 
LOG4CXX_STR("\\ufffd")); // The Unicode replacement character
-#elif LOG4CXX_LOGCHAR_IS_UTF8
-               // 0xD822 is encoded in UTF-8 as 0xED 0xA0 0xA2
-               
expectedQuotedEscapedName.insert(expectedQuotedEscapedName.size() - 1, 
"\xED\xA0\xA2");
+#else
+               
expectedQuotedEscapedName.insert(expectedQuotedEscapedName.size() - 1, 
LOG4CXX_STR("\\ufffd")); // The Unicode replacement character
 #endif
                LogString escapedQuoted0xD822Name;
                appendQuotedEscapedString(escapedQuoted0xD822Name, 
problemNameLS);

Reply via email to