Skip to content

Commit ea0178a

Browse files
authored
Merge pull request mackerelio#790 from kmuto/utf16le-fix
fix the line handling of UTF-16le
2 parents c93dad2 + d96d909 commit ea0178a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

check-log/lib/check-log.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,15 @@ func (opts *logOpts) searchReader(ctx context.Context, rdr io.Reader) (warnNum,
353353
readBytes += int64(len(lineBytes))
354354

355355
if opts.decoder != nil {
356+
if opts.Encoding == "UTF-16le" {
357+
// Separating UTF-16 little endian lines by byte 0x0a ("\n")
358+
// leaves 0x00 at the beginning of second line onwards. Remove it.
359+
if lineBytes[0] == 0x00 {
360+
lineBytes = lineBytes[1:]
361+
}
362+
// Since it ends with 0x0a, use 0x0a 0x00 as UTF-16 little endian
363+
lineBytes = append(lineBytes, 0x00)
364+
}
356365
lineBytes, err = opts.decoder.Bytes(lineBytes)
357366
if err != nil {
358367
break

0 commit comments

Comments
 (0)