From ef2ac676807bba20ba19dd9e4c7e44b6a96098a4 Mon Sep 17 00:00:00 2001 From: aiq Date: Fri, 18 Feb 2022 22:37:52 +0100 Subject: [PATCH] handle also \r\n as newline at the end of the content --- Reader.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Reader.go b/Reader.go index 6dbacba..0b64b12 100644 --- a/Reader.go +++ b/Reader.go @@ -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 != "" { @@ -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.