tolerate bare newlines in gophermap parsing (non CRLF)

This commit is contained in:
tjp 2024-01-14 19:53:10 -07:00
parent 4d861a2c39
commit 751f423f11
1 changed files with 3 additions and 6 deletions

View File

@ -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)
}