Skip to content

Commit

Permalink
Don't crash for an empty user agent string.
Browse files Browse the repository at this point in the history
Sadly I never thought of this case before... Thanks @edhgoose for the bug
report. Fixes #7.
  • Loading branch information
mssola committed May 24, 2013
1 parent 8583d30 commit 0a1650f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 7 additions & 5 deletions user_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
}
}

Expand Down

0 comments on commit 0a1650f

Please sign in to comment.