diff --git a/all_test.go b/all_test.go index db760f9..d61a659 100644 --- a/all_test.go +++ b/all_test.go @@ -49,6 +49,7 @@ var uastrings = []struct { {"OperaNested", "Opera/9.80 (Windows NT 5.1; MRA 6.0 (build 5831)) Presto/2.12.388 Version/12.10"}, // Other + {"Empty", ""}, {"Nil", "nil"}, {"Compatible", "Mozilla/4.0 (compatible)"}, {"Mozilla", "Mozilla/5.0"}, @@ -112,6 +113,7 @@ var expected = []string{ "Platform:Windows OS:Windows XP Browser:Opera-9.80 Engine:Presto-2.12.388 Bot:false Mobile:false", // Other + "Bot:false Mobile:false", "Browser:nil Bot:true Mobile:true", "Mozilla:4.0 Bot:false Mobile:false", "Mozilla:5.0 Bot:false Mobile:false", diff --git a/user_agent.go b/user_agent.go index 3867013..40256a4 100644 --- a/user_agent.go +++ b/user_agent.go @@ -118,11 +118,13 @@ func (p *UserAgent) Parse(ua string) { sections = append(sections, s) } - p.mozilla = sections[0].version - p.checkBot(sections[0].comment) - if !p.bot { - p.detectBrowser(sections) - p.detectOS(sections[0]) + if len(sections) > 0 { + p.mozilla = sections[0].version + p.checkBot(sections[0].comment) + if !p.bot { + p.detectBrowser(sections) + p.detectOS(sections[0]) + } } }