From d40dd3a4d38d23a5bd7477f09cf67074a48c4252 Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Tue, 1 Jul 2025 17:45:12 -0700 Subject: [PATCH] frontend: handle protocol names with dash --- frontend/template.go | 2 +- frontend/template_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/template.go b/frontend/template.go index 069c7e0..d9cd181 100644 --- a/frontend/template.go +++ b/frontend/template.go @@ -76,7 +76,7 @@ func (r SummaryRowData) ProtocolMatches(protocols []string) bool { } // pre-compiled regexp and constant statemap for summary rendering -var splitSummaryLine = regexp.MustCompile(`(\w+)\s+(\w+)\s+([\w-]+)\s+(\w+)\s+([0-9\-\. :]+)(.*)`) +var splitSummaryLine = regexp.MustCompile(`^([\w-]+)\s+(\w+)\s+([\w-]+)\s+(\w+)\s+([0-9\-\. :]+)(.*)$`) var summaryStateMap = map[string]string{ "up": "success", "down": "secondary", diff --git a/frontend/template_test.go b/frontend/template_test.go index 97b7e17..6893db6 100644 --- a/frontend/template_test.go +++ b/frontend/template_test.go @@ -76,3 +76,14 @@ func TestSummaryRowDataFromLineBGPPassive(t *testing.T) { assert.Equal(t, data.Since, "2025-06-27 21:23:08") assert.Equal(t, data.Info, "Passive") } + +func TestSummaryRowDataFromLineWithDash(t *testing.T) { + data := SummaryRowDataFromLine("ibgp_test-01 BGP --- up 07:16:51.656 Established") + + assert.Equal(t, data.Name, "ibgp_test-01") + assert.Equal(t, data.Proto, "BGP") + assert.Equal(t, data.Table, "---") + assert.Equal(t, data.State, "up") + assert.Equal(t, data.Since, "07:16:51.656") + assert.Equal(t, data.Info, "Established") +}