From 02163655515ab3b8f635ac390082d428a44bd323 Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Tue, 27 Oct 2020 22:59:11 +0800 Subject: [PATCH] frontend: improve robustness handling errors --- frontend/render.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/frontend/render.go b/frontend/render.go index 6bb09d2..c917967 100644 --- a/frontend/render.go +++ b/frontend/render.go @@ -120,13 +120,28 @@ func summaryTable(isIPv6 bool, data string, serverName string) string { // Parse a total of 6 columns from bird summary lineSplitted := regexp.MustCompile(`(\w+)(\s+)(\w+)(\s+)([\w-]+)(\s+)(\w+)(\s+)([0-9\-\. :]+)(.*)`).FindStringSubmatch(line) - var row = [6]string{ - strings.TrimSpace(lineSplitted[1]), - strings.TrimSpace(lineSplitted[3]), - strings.TrimSpace(lineSplitted[5]), - strings.TrimSpace(lineSplitted[7]), - strings.TrimSpace(lineSplitted[9]), - strings.TrimSpace(lineSplitted[10]), + if lineSplitted == nil { + continue + } + + var row [6]string + if len(lineSplitted) >= 2 { + row[0] = strings.TrimSpace(lineSplitted[1]) + } + if len(lineSplitted) >= 4 { + row[1] = strings.TrimSpace(lineSplitted[3]) + } + if len(lineSplitted) >= 6 { + row[2] = strings.TrimSpace(lineSplitted[5]) + } + if len(lineSplitted) >= 8 { + row[3] = strings.TrimSpace(lineSplitted[7]) + } + if len(lineSplitted) >= 10 { + row[4] = strings.TrimSpace(lineSplitted[9]) + } + if len(lineSplitted) >= 11 { + row[5] = strings.TrimSpace(lineSplitted[10]) } // Draw the row in red if the link isn't up