diff options
author | tjp <tjp@ctrl-c.club> | 2024-01-14 19:53:10 -0700 |
---|---|---|
committer | tjp <tjp@ctrl-c.club> | 2024-01-14 19:53:10 -0700 |
commit | 751f423f11bf6fd848a074b2575cc00fdb6c3bad (patch) | |
tree | 5599c5ca1afb995a557b99dab4801a633c3ad2ad /gopher | |
parent | 4d861a2c395c0926b066014b92999d4dda454b2b (diff) |
tolerate bare newlines in gophermap parsing (non CRLF)
Diffstat (limited to 'gopher')
-rw-r--r-- | gopher/gophermap/parse.go | 9 |
1 files 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) } |