Skip to content

Fix journalctl JSON parsing for byte-array MESSAGE fields#616

Open
sfc-gh-mjankowski wants to merge 1 commit intomainfrom
mjankowski-improve-journalctl-json-parsing
Open

Fix journalctl JSON parsing for byte-array MESSAGE fields#616
sfc-gh-mjankowski wants to merge 1 commit intomainfrom
mjankowski-improve-journalctl-json-parsing

Conversation

@sfc-gh-mjankowski
Copy link
Copy Markdown
Collaborator

@sfc-gh-mjankowski sfc-gh-mjankowski commented Apr 2, 2026

Summary

  • Fix json: cannot unmarshal array into Go value of type string when journalctl --output=json encodes binary/non-UTF8 fields (e.g. MESSAGE) as byte arrays instead of strings
  • Change unmarshal target from map[string]string to map[string]any, convert values back to strings with non-printable character sanitization
  • No proto, client, or wire format changes

Test plan

  • TestJournalByteArrayRegression proves the old code fails and the new code succeeds
  • TestJournalValueToString covers: string passthrough, valid byte arrays, non-printable sanitization, high bytes, boundary values, invalid arrays (mixed types, out-of-range), unexpected JSON types
  • TestSanitizeString covers: printable ASCII, whitespace preservation, control chars, invalid UTF-8, multibyte
  • TestJournalEntryToStringMap covers: mixed types, empty map, multiple byte-array fields, JSON number values
  • TestJournalByteArrayMessage end-to-end through gRPC server (raw + structured modes)
  • Existing TestJournal cases still pass (no regression on normal string entries)

@sfc-gh-mjankowski sfc-gh-mjankowski force-pushed the mjankowski-improve-journalctl-json-parsing branch from c735b69 to c1bba96 Compare April 2, 2026 14:40
@sfc-gh-mjankowski sfc-gh-mjankowski force-pushed the mjankowski-improve-journalctl-json-parsing branch from c1bba96 to 5dbb798 Compare April 3, 2026 07:21
@sfc-gh-mjankowski sfc-gh-mjankowski marked this pull request as ready for review April 3, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants