From 69c5336ea11aa51e2b47526f7d6108ac42ddcef1 Mon Sep 17 00:00:00 2001 From: tjp Date: Wed, 3 Jan 2024 20:15:11 -0700 Subject: optional tabs for gopher i lines --- gopher/gophermap/parse.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gopher/gophermap/parse.go b/gopher/gophermap/parse.go index 04286bd..e99fec6 100644 --- a/gopher/gophermap/parse.go +++ b/gopher/gophermap/parse.go @@ -32,15 +32,22 @@ func Parse(input io.Reader) (gopher.MapDocument, error) { item := gopher.MapItem{Type: sr.Status(line[0])} spl := bytes.Split(line[1:len(line)-2], []byte{'\t'}) - if len(spl) != 4 { + if item.Type != gopher.InfoMessageType && len(spl) != 4 { return nil, InvalidLine(num) } item.Display = string(spl[0]) - item.Selector = string(spl[1]) - item.Hostname = string(spl[2]) - item.Port = string(spl[3]) - if _, err = strconv.Atoi(item.Port); err != nil { - return nil, InvalidLine(num) + + if len(spl) > 1 { + item.Selector = string(spl[1]) + } + if len(spl) > 2 { + item.Hostname = string(spl[2]) + } + if len(spl) > 3 { + item.Port = string(spl[3]) + if _, err = strconv.Atoi(item.Port); err != nil { + return nil, InvalidLine(num) + } } doc = append(doc, item) -- cgit v1.2.3