chore: fix user agent parsing for unset wakatime version (resolve #306) [ci skip]

This commit is contained in:
Ferdinand Mütsch 2022-01-12 21:23:36 +01:00
parent 4a3fe48cce
commit 03b104a390
3 changed files with 8 additions and 2 deletions

View File

@ -46,7 +46,7 @@ func Add(i, j int) int {
}
func ParseUserAgent(ua string) (string, string, error) {
re := regexp.MustCompile(`(?iU)^wakatime\/v?[\d+.]+\s\((\w+)-.*\)\s.+\s([^\/\s]+)-wakatime\/.+$`)
re := regexp.MustCompile(`(?iU)^wakatime\/(?:v?[\d+.]+|unset)\s\((\w+)-.*\)\s.+\s([^\/\s]+)-wakatime\/.+$`)
groups := re.FindAllStringSubmatch(ua, -1)
if len(groups) == 0 || len(groups[0]) != 3 {
return "", "", errors.New("failed to parse user agent string")

View File

@ -43,6 +43,12 @@ func TestCommon_ParseUserAgent(t *testing.T) {
"emacs",
nil,
},
{
"wakatime/unset (linux-5.11.0-44-generic-x86_64) go1.16.13 emacs-wakatime/1.0.2",
"linux",
"emacs",
nil,
},
}
for _, test := range tests {

View File

@ -1 +1 @@
2.0.0
2.0.1