From 751f423f11bf6fd848a074b2575cc00fdb6c3bad Mon Sep 17 00:00:00 2001 From: tjp Date: Sun, 14 Jan 2024 19:53:10 -0700 Subject: [PATCH] tolerate bare newlines in gophermap parsing (non CRLF) --- gopher/gophermap/parse.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/gopher/gophermap/parse.go b/gopher/gophermap/parse.go index e99fec6..daa458b 100644 --- a/gopher/gophermap/parse.go +++ b/gopher/gophermap/parse.go @@ -24,14 +24,11 @@ func Parse(input io.Reader) (gopher.MapDocument, error) { return nil, err } - if len(line) > 2 && !bytes.Equal(line, []byte(".\r\n")) { - if line[len(line)-2] != '\r' || line[len(line)-1] != '\n' { - return nil, InvalidLine(num) - } - + line = bytes.TrimSuffix(bytes.TrimSuffix(line, []byte{'\n'}), []byte{'\r'}) + if len(line) > 0 && !bytes.Equal(line, []byte(".")) { item := gopher.MapItem{Type: sr.Status(line[0])} - spl := bytes.Split(line[1:len(line)-2], []byte{'\t'}) + spl := bytes.Split(line[1:], []byte{'\t'}) if item.Type != gopher.InfoMessageType && len(spl) != 4 { return nil, InvalidLine(num) }