Skip to content
This repository was archived by the owner on Feb 17, 2023. It is now read-only.

Commit 68da1a7

Browse files
authored
Merge pull request #48 from dbertouille/master
Facebook App Handling
2 parents a0de238 + 5723c36 commit 68da1a7

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

all_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,16 @@ var uastrings = []struct {
534534
ua: "Dalvik/1.6.0 (Linux; U; Android 4.0.4; W2430 Build/IMM76D)014; Profile/MIDP-2.1 Configuration/CLDC-1",
535535
expected: "Mozilla:5.0 Platform:Linux OS:Android 4.0.4 Bot:false Mobile:true",
536536
},
537+
{
538+
title: "Samsung S5 Facebook App",
539+
ua: "Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/43.0.2357.121 Mobile Safari/537.36 [FB_IAB/FB4A;FBAV/35.0.0.48.273;]",
540+
expected: "Mozilla:5.0 Platform:Linux OS:Android 5.0 Localization:wv Browser:Android-4.0 Engine:AppleWebKit-537.36 Bot:false Mobile:true",
541+
},
542+
{
543+
title: "Facebook - No Browser Or OS",
544+
ua: "[FBAN/FB4A;FBAV/16.0.0.20.15;FBBV/4061184;FBDM/{density=1.5,width=540,height=960};FBLC/en_US;FB_FW/2;FBCR/MY CELCOM;FBPN/com.facebook.katana;FBDV/Lenovo A850+;FBSV/4.2.2;FBOP/1;FBCA/armeabi-v7a:armeabi;]",
545+
expected: "Bot:false Mobile:false",
546+
},
537547
}
538548

539549
// Internal: beautify the UserAgent reference into a string so it can be

user_agent.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,27 @@ func parseProduct(product []byte) (string, string) {
8585
// Returns a section containing the information that we could extract
8686
// from the last parsed section.
8787
func parseSection(ua string, index *int) (s section) {
88-
buffer := readUntil(ua, index, ' ', false)
88+
var buffer []byte
89+
90+
// Check for empty products
91+
if *index < len(ua) && ua[*index] != '(' && ua[*index] != '[' {
92+
buffer = readUntil(ua, index, ' ', false)
93+
s.name, s.version = parseProduct(buffer)
94+
}
8995

90-
s.name, s.version = parseProduct(buffer)
9196
if *index < len(ua) && ua[*index] == '(' {
9297
*index++
9398
buffer = readUntil(ua, index, ')', true)
9499
s.comment = strings.Split(string(buffer), "; ")
95100
*index++
96101
}
102+
103+
// Discards any trailing data within square brackets
104+
if *index < len(ua) && ua[*index] == '[' {
105+
*index++
106+
buffer = readUntil(ua, index, ']', true)
107+
*index++
108+
}
97109
return s
98110
}
99111

0 commit comments

Comments
 (0)