mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: support user agents set by browser plugin (see #237)
This commit is contained in:
@@ -49,6 +49,12 @@ func TestCommon_ParseUserAgent(t *testing.T) {
|
||||
"emacs",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"Chrome/111.0.0.0 chrome-wakatime/3.0.6",
|
||||
"",
|
||||
"chrome",
|
||||
nil,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
@@ -78,7 +78,7 @@ func ParsePageParamsWithDefault(r *http.Request, page, size int) *PageParams {
|
||||
}
|
||||
|
||||
func ParseUserAgent(ua string) (string, string, error) {
|
||||
re := regexp.MustCompile(`(?iU)^wakatime\/(?:v?[\d+.]+|unset)\s\((\w+)-.*\)\s.+\s([^\/\s]+)-wakatime\/.+$`)
|
||||
re := regexp.MustCompile(`(?iU)^(?:(?:wakatime|chrome|firefox)\/(?: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")
|
||||
|
Reference in New Issue
Block a user