Handle more invalid user agents

This commit is contained in:
Martin Polden 2017-05-28 13:57:48 +02:00
parent 0cd84ada1e
commit f644b0b488
2 changed files with 3 additions and 1 deletions

View File

@ -15,7 +15,7 @@ func Parse(s string) UserAgent {
var version, comment string
if len(parts) > 1 {
// If first character is a number, treat it as version
if parts[1][0] >= 48 && parts[1][0] <= 57 {
if len(parts[1]) > 0 && parts[1][0] >= 48 && parts[1][0] <= 57 {
rest := strings.SplitN(parts[1], " ", 2)
version = rest[0]
if len(rest) > 1 {

View File

@ -10,6 +10,8 @@ func TestParse(t *testing.T) {
out UserAgent
}{
{"", UserAgent{}},
{"curl/", UserAgent{Product: "curl"}},
{"curl/foo", UserAgent{Product: "curl", Comment: "foo"}},
{"curl/7.26.0", UserAgent{Product: "curl", Version: "7.26.0"}},
{"Wget/1.13.4 (linux-gnu)", UserAgent{Product: "Wget", Version: "1.13.4", Comment: "(linux-gnu)"}},
{"Wget", UserAgent{Product: "Wget"}},