diff --git a/clientTag.go b/clientTag.go index 90bb671..89a2746 100644 --- a/clientTag.go +++ b/clientTag.go @@ -1,6 +1,7 @@ package main import ( + "regexp" "strings" ) @@ -9,6 +10,10 @@ type clientTag struct { Version string } +var ( + rx_bestNumberPart = regexp.MustCompile(`[0-9\.]+`) +) + func parseVersion(ver string) clientTag { // Try our best to turn the supplied text into a structured version ret := clientTag{ @@ -39,9 +44,10 @@ func parseVersion(ver string) clientTag { } } - // Strip leading v from mIRC - if len(ret.Version) >= 2 && (ret.Version[0] == 'v' || ret.Version[0] == 'V') && strings.ContainsAny(string(ret.Version[1]), "0123456789") { - ret.Version = ret.Version[1:] + // We only support digits, periods, and hyphens in the number part + // This removes the leading v from mIRC and the trailing deb** from irssi + if submatch := rx_bestNumberPart.FindStringSubmatch(ret.Version); len(submatch) == 1 { + ret.Version = submatch[0] } // Special case: "Relay" means "HoloIRC" diff --git a/clientTag_test.go b/clientTag_test.go index cd62ebc..d716247 100644 --- a/clientTag_test.go +++ b/clientTag_test.go @@ -47,6 +47,11 @@ func TestParseVersion(t *testing.T) { "Revolution IRC:0.3.2:Android", "Revolution IRC", "0.3.2", }, + + [3]string{ + "irssi v1.0.2-1+deb9u3", + "irssi", "1.0.2", + }, } for _, test := range tests {