Skip to content

Commit

Permalink
fix: handle non zero terminated payload strings
Browse files Browse the repository at this point in the history
Most strings seem to have a trailing zero but some dont. For those the last
char was dropped.
  • Loading branch information
mbehr1 committed May 9, 2021
1 parent 78c9eee commit 5b27f96
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/dltParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ export class DltMsg {
const strLenInclTerm: number = this._payloadData.readUInt16LE(argOffset);
argOffset += 2;
if (strLenInclTerm > 0 && strLenInclTerm < 2000) { // some sanity check...
let strText = this._payloadData.toString((scod === 1 ? "utf8" : "latin1"), argOffset, argOffset + strLenInclTerm - 1);
const gotTerm = this._payloadData[argOffset + strLenInclTerm - 1] === 0 ? 1 : 0;
let strText = this._payloadData.toString((scod === 1 ? "utf8" : "latin1"), argOffset, argOffset + strLenInclTerm - gotTerm);
// replace CRLF with ' '
// todo assemble payloadAsText ... msgText += strText.replace(/(\r\n|\n|\r)/gm, " "); // this is slow...
this._payloadArgs.push({ type: String, v: strText });
Expand Down

0 comments on commit 5b27f96

Please sign in to comment.