diff options
-rw-r--r-- | gopher/gophermap/parse.go | 19 |
1 files 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) |