vy commented on a change in pull request #444:
URL: https://github.com/apache/logging-log4j2/pull/444#discussion_r532463858



##########
File path: 
log4j-layout-template-json/src/main/java/org/apache/logging/log4j/layout/template/json/util/JsonWriter.java
##########
@@ -513,18 +509,15 @@ public void writeString(final StringBuilderFormattable 
formattable) {
             writeNull();
         } else {
             stringBuilder.append('"');
-            formattableBuffer.setLength(0);
-            formattable.formatTo(formattableBuffer);
-            final int length = formattableBuffer.length();
-            // Handle max. string length complying input.
-            if (length <= maxStringLength) {
-                quoteString(formattableBuffer, 0, length);
-            }
+            int position = stringBuilder.length();
+            formattable.formatTo(stringBuilder);
+            final int length = stringBuilder.length() - position;
             // Handle max. string length violating input.
-            else {
-                quoteString(formattableBuffer, 0, maxStringLength);
+            if (length > maxStringLength) {
+                stringBuilder.setLength(position + maxStringLength);
                 stringBuilder.append(quotedTruncatedStringSuffix);
             }
+            StringBuilders.escapeJson(stringBuilder, position);
             stringBuilder.append('"');

Review comment:
       My comment above regarding `StringBuilders.escapeJson()` applies here 
too.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to