mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: compatible with new wakatime-cli
This commit is contained in:
parent
f399fd4ea7
commit
825663acde
@ -46,7 +46,7 @@ func Add(i, j int) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ParseUserAgent(ua string) (string, string, error) {
|
func ParseUserAgent(ua string) (string, string, error) {
|
||||||
re := regexp.MustCompile(`(?iU)^wakatime\/[\d+.]+\s\((\w+)-.*\)\s.+\s([^\/\s]+)-wakatime\/.+$`)
|
re := regexp.MustCompile(`(?iU)^wakatime\/v?[\d+.]+\s\((\w+)-.*\)\s.+\s([^\/\s]+)-wakatime\/.+$`)
|
||||||
groups := re.FindAllStringSubmatch(ua, -1)
|
groups := re.FindAllStringSubmatch(ua, -1)
|
||||||
if len(groups) == 0 || len(groups[0]) != 3 {
|
if len(groups) == 0 || len(groups[0]) != 3 {
|
||||||
return "", "", errors.New("failed to parse user agent string")
|
return "", "", errors.New("failed to parse user agent string")
|
||||||
|
@ -37,6 +37,12 @@ func TestCommon_ParseUserAgent(t *testing.T) {
|
|||||||
"",
|
"",
|
||||||
errors.New(""),
|
errors.New(""),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"wakatime/v1.18.11 (linux-5.13.8-200.fc34.x86_64-x86_64) go1.16.7 emacs-wakatime/1.0.2",
|
||||||
|
"linux",
|
||||||
|
"emacs",
|
||||||
|
nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
Loading…
Reference in New Issue
Block a user