Handle byte-array encoded journal data

Journalctl json output formats field values as JSON strings with the
exception:

  Fields containing non-printable or non-UTF8 bytes are encoded as arrays
  containing the raw bytes individually formatted as unsigned numbers.
This commit is contained in:
Justin Stephenson 2020-04-15 10:36:34 -04:00
parent 564c9c25f7
commit 198e49cfff

View file

@ -439,10 +439,10 @@ let PacketBuffer = class {
}
}
if (in_txt_pos < in_txt.length) {
if (in_txt_pos < [...in_txt].length) {
this.reportError(_("extra input present"));
}
if (out_txt_pos < out_txt.length) {
if (out_txt_pos < [...out_txt].length) {
this.reportError(_("extra output present"));
}
@ -525,7 +525,17 @@ let PacketBuffer = class {
}
/* Parse the entry message */
try {
this.parseMessage(JSON.parse(e['MESSAGE']));
let utf8decoder = new TextDecoder();
/* Journalctl stores fields with non-printable characters
* in an array of raw bytes formatted as unsigned
* integers */
if (Array.isArray(e['MESSAGE'])) {
let u8arr = new Uint8Array(e['MESSAGE']);
this.parseMessage(JSON.parse(utf8decoder.decode(u8arr)));
} else {
this.parseMessage(JSON.parse(e['MESSAGE']));
}
} catch (error) {
this.handleError(error);
return;