Skip to content

Commit 169a776

Browse files
author
dmsa0618
committed
fix issue with standard delimiter in line start
1 parent 22cd07d commit 169a776

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

tailer/fswatcher/linereader.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package fswatcher
1717
import (
1818
"io"
1919
"regexp"
20+
"strings"
2021
)
2122

2223
type lineReader struct {
@@ -62,13 +63,13 @@ func (r *lineReader) ReadLine(file io.Reader) (string, bool, error) {
6263
copy(result, r.remainingBytesFromLastRead[:newlinePos])
6364
copy(r.remainingBytesFromLastRead, r.remainingBytesFromLastRead[newlinePos+1:])
6465
r.remainingBytesFromLastRead = r.remainingBytesFromLastRead[:l-(newlinePos+1)]
65-
return string(stripWindowsLineEnding(result)), false, nil
66+
return stripLineEnding(string(result)), false, nil
6667
} else if err != nil {
6768
if err == io.EOF {
6869
result := make([]byte, len(r.remainingBytesFromLastRead))
6970
copy(result, r.remainingBytesFromLastRead)
7071
r.remainingBytesFromLastRead = []byte{}
71-
return string(stripWindowsLineEnding(result)), true, nil
72+
return stripLineEnding(string(result)), true, nil
7273
} else {
7374
return "", false, err
7475
}
@@ -82,12 +83,11 @@ func (r *lineReader) ReadLine(file io.Reader) (string, bool, error) {
8283
}
8384
}
8485

85-
func stripWindowsLineEnding(s []byte) []byte {
86-
if len(s) > 0 && s[len(s)-1] == '\r' {
87-
return s[:len(s)-1]
88-
} else {
89-
return s
90-
}
86+
func stripLineEnding(s string) string {
87+
// in standard delimiter case
88+
s = strings.TrimPrefix(s, "\n")
89+
s = strings.TrimSuffix(s, "\r")
90+
return s
9191
}
9292

9393
func (r *lineReader) Clear() {

0 commit comments

Comments
 (0)