Skip to content

Commit

Permalink
Fix #208 invalid json on extended fields
Browse files Browse the repository at this point in the history
  • Loading branch information
agentgt committed Jan 6, 2025
1 parent 083e7df commit 2a2cf4a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,21 @@ private final void _writeStartField(String k, int index, int flag) {
}
if (prettyPrint) {
jsonWriter.writeByte(LF);
}
if (prettyPrint) {
jsonWriter.writeByte(SPACE);
}
if ((flag & EXTENDED_F) == EXTENDED_F) {
/*
* TODO on minor version offer a prefix suffix write as this is probably less
* efficient. https://github.com/jstachio/rainbowgum/issues/208
*/
jsonWriter.writeByte(RawJsonWriter.QUOTE);
jsonWriter.writeByte(extendedFieldPrefix.raw);
jsonWriter.writeAscii(k);
jsonWriter.writeByte(RawJsonWriter.QUOTE);
}
else {
jsonWriter.writeAsciiString(k);
}
jsonWriter.writeAsciiString(k);
jsonWriter.writeByte(SEMI);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import io.jstach.rainbowgum.LogOutput.ContentType.StandardContentType;
import io.jstach.rainbowgum.annotation.GeneratedByATrustedSource;

/*
* This code was largely inspired a long time ago
* by DSL platform JSON writer.
* https://github.com/ngs-doo/dsl-json
*/
class RawJsonWriter {

private int position;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void testBuilder() {
"_logger":"gelf",
"_thread_name":"main",
"_thread_id":"1",
_"header1":"1",
"_header1":"1",
"version":"1.1"
}
""";
Expand Down Expand Up @@ -285,8 +285,8 @@ String message() {
"_logger":"gelf",
"_thread_name":"main",
"_thread_id":"1",
_"k1":"v1",
_"k2":"v2",
"_k1":"v1",
"_k2":"v2",
"version":"1.1"
}
""")
Expand Down

0 comments on commit 2a2cf4a

Please sign in to comment.