doc: fix bad numeric version for irssi, add clientTag test

--HG--
branch : nmdc-ircfrontend
This commit is contained in:
mappu 2018-03-24 15:24:52 +13:00
parent e9ad8f6962
commit 19e0120423
2 changed files with 14 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"regexp"
"strings" "strings"
) )
@ -9,6 +10,10 @@ type clientTag struct {
Version string Version string
} }
var (
rx_bestNumberPart = regexp.MustCompile(`[0-9\.]+`)
)
func parseVersion(ver string) clientTag { func parseVersion(ver string) clientTag {
// Try our best to turn the supplied text into a structured version // Try our best to turn the supplied text into a structured version
ret := clientTag{ ret := clientTag{
@ -39,9 +44,10 @@ func parseVersion(ver string) clientTag {
} }
} }
// Strip leading v from mIRC // We only support digits, periods, and hyphens in the number part
if len(ret.Version) >= 2 && (ret.Version[0] == 'v' || ret.Version[0] == 'V') && strings.ContainsAny(string(ret.Version[1]), "0123456789") { // This removes the leading v from mIRC and the trailing deb** from irssi
ret.Version = ret.Version[1:] if submatch := rx_bestNumberPart.FindStringSubmatch(ret.Version); len(submatch) == 1 {
ret.Version = submatch[0]
} }
// Special case: "Relay" means "HoloIRC" // Special case: "Relay" means "HoloIRC"

View File

@ -47,6 +47,11 @@ func TestParseVersion(t *testing.T) {
"Revolution IRC:0.3.2:Android", "Revolution IRC:0.3.2:Android",
"Revolution IRC", "0.3.2", "Revolution IRC", "0.3.2",
}, },
[3]string{
"irssi v1.0.2-1+deb9u3",
"irssi", "1.0.2",
},
} }
for _, test := range tests { for _, test := range tests {