You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by cakofony <gi...@git.apache.org> on 2017/11/06 18:50:59 UTC
[GitHub] logging-log4j2 pull request #125: LOG4J2-2102: MapMessage Json encoding esca...
GitHub user cakofony opened a pull request:
https://github.com/apache/logging-log4j2/pull/125
LOG4J2-2102: MapMessage Json encoding escapes key and value strings
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/cakofony/logging-log4j2 LOG4J2-2102
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/logging-log4j2/pull/125.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #125
----
commit 163f3db588b4b46a9bbddbd28f64fb65b5e4e292
Author: Carter Kozak <c4...@gmail.com>
Date: 2017-11-06T18:49:36Z
LOG4J2-2102: MapMessage Json encoding escapes key and value strings
----
---
[GitHub] logging-log4j2 pull request #125: LOG4J2-2102: MapMessage Json encoding esca...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:
https://github.com/apache/logging-log4j2/pull/125
---
[GitHub] logging-log4j2 issue #125: LOG4J2-2102: MapMessage Json encoding escapes key...
Posted by cakofony <gi...@git.apache.org>.
Github user cakofony commented on the issue:
https://github.com/apache/logging-log4j2/pull/125
Feel free to close this in favor of #129 if you prefer to iterate there.
---
[GitHub] logging-log4j2 issue #125: LOG4J2-2102: MapMessage Json encoding escapes key...
Posted by mikaelstaldal <gi...@git.apache.org>.
Github user mikaelstaldal commented on the issue:
https://github.com/apache/logging-log4j2/pull/125
We should do the same for the XML format, you can use the new XML format in `EncodingPatternConverter` for that (pull from master). Good to place that in a shared utility class.
---
[GitHub] logging-log4j2 issue #125: LOG4J2-2102: MapMessage Json encoding escapes key...
Posted by cakofony <gi...@git.apache.org>.
Github user cakofony commented on the issue:
https://github.com/apache/logging-log4j2/pull/125
Updated, thanks!
---
[GitHub] logging-log4j2 pull request #125: LOG4J2-2102: MapMessage Json encoding esca...
Posted by cakofony <gi...@git.apache.org>.
Github user cakofony commented on a diff in the pull request:
https://github.com/apache/logging-log4j2/pull/125#discussion_r149168416
--- Diff: log4j-core/src/main/java/org/apache/logging/log4j/core/pattern/EncodingPatternConverter.java ---
@@ -86,100 +87,4 @@ public void format(final LogEvent event, final StringBuilder toAppendTo) {
}
escapeFormat.escape(toAppendTo, start);
}
-
- private enum EscapeFormat {
- HTML {
- @Override
- void escape(final StringBuilder toAppendTo, final int start) {
- for (int i = toAppendTo.length() - 1; i >= start; i--) { // backwards: length may change
- final char c = toAppendTo.charAt(i);
- switch (c) {
- case '\r':
- toAppendTo.setCharAt(i, '\\');
- toAppendTo.insert(i + 1, 'r');
- break;
- case '\n':
- toAppendTo.setCharAt(i, '\\');
- toAppendTo.insert(i + 1, 'n');
- break;
- case '&':
- toAppendTo.setCharAt(i, '&');
- toAppendTo.insert(i + 1, "amp;");
- break;
- case '<':
- toAppendTo.setCharAt(i, '&');
- toAppendTo.insert(i + 1, "lt;");
- break;
- case '>':
- toAppendTo.setCharAt(i, '&');
- toAppendTo.insert(i + 1, "gt;");
- break;
- case '"':
- toAppendTo.setCharAt(i, '&');
- toAppendTo.insert(i + 1, "quot;");
- break;
- case '\'':
- toAppendTo.setCharAt(i, '&');
- toAppendTo.insert(i + 1, "apos;");
- break;
- case '/':
- toAppendTo.setCharAt(i, '&');
- toAppendTo.insert(i + 1, "#x2F;");
- break;
- }
- }
- }
- },
-
- /**
- * JSON string escaping as defined in RFC 4627.
- *
- * @see <a href="https://www.ietf.org/rfc/rfc4627.txt">RFC 4627</a>
- */
- JSON {
- @Override
- void escape(final StringBuilder toAppendTo, final int start) {
- for (int i = toAppendTo.length() - 1; i >= start; i--) { // backwards: length may change
- final char c = toAppendTo.charAt(i);
- if (Character.isISOControl(c)) {
- // all iso control characters are in U+00xx
- toAppendTo.setCharAt(i, '\\');
- toAppendTo.insert(i + 1, "u0000");
- toAppendTo.setCharAt(i + 4, Chars.getUpperCaseHex((c & 0xF0) >> 4));
- toAppendTo.setCharAt(i + 5, Chars.getUpperCaseHex(c & 0xF));
- } else if (c == '"' || c == '\\') {
- // only " and \ need to be escaped; other escapes are optional
- toAppendTo.insert(i, '\\');
- }
- }
- }
- },
-
- CRLF {
- @Override
- void escape(final StringBuilder toAppendTo, final int start) {
- for (int i = toAppendTo.length() - 1; i >= start; i--) { // backwards: length may change
- final char c = toAppendTo.charAt(i);
- switch (c) {
- case '\r':
- toAppendTo.setCharAt(i, '\\');
- toAppendTo.insert(i + 1, 'r');
- break;
- case '\n':
- toAppendTo.setCharAt(i, '\\');
- toAppendTo.insert(i + 1, 'n');
- break;
- }
- }
- }
- };
-
- /**
- * Escapes text using a standardized format from a given starting point to the end of the string.
- *
- * @param toAppendTo string buffer to escape
- * @param start where to start escaping from
- */
- abstract void escape(final StringBuilder toAppendTo, final int start);
- }
--- End diff --
Alternatively I can pull the json implementation into a shared utility class elsewhere.
---