From 03b104a390cee45d596ccda4d2804829cf774de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Wed, 12 Jan 2022 21:23:36 +0100 Subject: [PATCH] chore: fix user agent parsing for unset wakatime version (resolve #306) [ci skip] --- utils/common.go | 2 +- utils/common_test.go | 6 ++++++ version.txt | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/utils/common.go b/utils/common.go index f873796..d3fa775 100644 --- a/utils/common.go +++ b/utils/common.go @@ -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") diff --git a/utils/common_test.go b/utils/common_test.go index 884d033..0772ceb 100644 --- a/utils/common_test.go +++ b/utils/common_test.go @@ -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 { diff --git a/version.txt b/version.txt index 359a5b9..10bf840 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.0.0 \ No newline at end of file +2.0.1 \ No newline at end of file