From f644b0b4885cebbb69e60e4a691d1265de46d00e Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Sun, 28 May 2017 13:57:48 +0200 Subject: [PATCH] Handle more invalid user agents --- useragent/useragent.go | 2 +- useragent/useragent_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/useragent/useragent.go b/useragent/useragent.go index e533662..e0de8e7 100644 --- a/useragent/useragent.go +++ b/useragent/useragent.go @@ -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 { diff --git a/useragent/useragent_test.go b/useragent/useragent_test.go index 14ff09a..b96acb7 100644 --- a/useragent/useragent_test.go +++ b/useragent/useragent_test.go @@ -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"}},