Skip to content

Conversation

@anatolym
Copy link

Fixes incorrect OSVersion extraction for ChromeOS user agents.

Repro for the latest version of the library (github.com/mileusna/[email protected])
https://go.dev/play/p/vmoU6OM9Juj

package main

import (
	"fmt"

	"github.com/mileusna/useragent"
)

func main() {
	userAgents := []string{
		"Mozilla/5.0 (X11; CrOS x86_64 14150.74.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.114 Safari/537.36",
		"Mozilla/5.0 (X11; CrOS armv7l 14388.62.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.107 Safari/537.36",
		"Mozilla/5.0 (X11; CrOS armv7l 14388.62.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.107 Safari/537.36",
		"Mozilla/5.0 (X11; CrOS x86_64 9460.60.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.91 Safari/537.36",
		"Mozilla/5.0 (X11; CrOS x86_64 11151.113.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.127 Safari/537.36",
		"Mozilla/5.0 (X11; CrOS x86_64 0.110.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3581.0 Safari/537.36",
		"Mozilla/5.0 (X11; CrOS x86_64 16209.59.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.7049.120 Safari/537.36",
	}

	for i, s := range userAgents {
		ua := useragent.Parse(s)
		fmt.Println(i, "\t", ua.OSVersion)
	}
}

// output:
// 0 	 x86_64
// 1 	 armv7l
// 2 	 armv7l
// 3 	 x86_64
// 4 	 x86_64
// 5 	 x86_64
// 6 	 x86_64

Output with the fix:

0 	 14150.74.0
1 	 14388.62.1
2 	 14388.62.1
3 	 9460.60.0
4 	 11151.113.0
5 	 0.110.0
6 	 16209.59.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant