mirror of https://github.com/mpolden/echoip
Handle more invalid user agents
This commit is contained in:
parent
0cd84ada1e
commit
f644b0b488
|
@ -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 {
|
||||
|
|
|
@ -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"}},
|
||||
|
|
Loading…
Reference in New Issue