Skip to content

Commit

Permalink
handle also \r\n as newline at the end of the content
Browse files Browse the repository at this point in the history
  • Loading branch information
aiq committed Feb 18, 2022
1 parent d666755 commit ef2ac67
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ func (my *Reader) readHeader() (Header, error) {
return header, nil
}

func trimLastNewLineSuffix(str string) string {
if strings.HasSuffix(str, "\r\n") {
return strings.TrimSuffix(str, "\r\n")
}
return strings.TrimSuffix(str, "\n")
}

func (my *Reader) readContent() (string, error) {
delim := "//"
if my.expPatt != "" {
Expand All @@ -128,7 +135,7 @@ func (my *Reader) readContent() (string, error) {
if err != nil && err != io.EOF {
return "", err
}
return strings.TrimSuffix(strings.TrimSuffix(cnt, delim), "\n"), nil
return trimLastNewLineSuffix(strings.TrimSuffix(cnt, delim)), nil
}

// ReadChunk reads one Chunk from r.
Expand Down

0 comments on commit ef2ac67

Please sign in to comment.