Skip to content

Commit 59f1cf6

Browse files
committed
Merge pull request selwin#5 from tonyseek/fixup-firefox-aurora
Fix up the parsing for Firefox Aurora in Android mobile device
2 parents 9329115 + 45b9b2c commit 59f1cf6

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎user_agents/parsers.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ def __init__(self, user_agent_string):
110110
def _is_android_tablet(self):
111111
# Newer Android tablets don't have "Mobile" in their user agent string,
112112
# older ones like Galaxy Tab still have "Mobile" though they're not
113-
if 'Mobile Safari' not in self.ua_string:
113+
if ('Mobile Safari' not in self.ua_string and
114+
self.browser.family != "Firefox Mobile"):
114115
return True
115116
if 'SCH-' in self.ua_string:
116117
return True
@@ -186,4 +187,4 @@ def is_bot(self):
186187

187188

188189
def parse(user_agent_string):
189-
return UserAgent(user_agent_string)
190+
return UserAgent(user_agent_string)

‎user_agents/tests.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
ubuntu_firefox_ua_string = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:15.0) Gecko/20100101 Firefox/15.0.1'
2525
google_bot_ua_string = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)'
2626
nokia_n97_ua_string = 'Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/12.0.024; Profile/MIDP-2.1 Configuration/CLDC-1.1; en-us) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.12344'
27+
android_firefox_aurora_ua_string = 'Mozilla/5.0 (Android; Mobile; rv:27.0) Gecko/27.0 Firefox/27.0'
2728

2829
iphone_ua = parse(iphone_ua_string)
2930
ipad_ua = parse(ipad_ua_string)
@@ -45,6 +46,7 @@
4546
ubuntu_firefox_ua = parse(ubuntu_firefox_ua_string)
4647
google_bot_ua = parse(google_bot_ua_string)
4748
nokia_n97_ua = parse(nokia_n97_ua_string)
49+
android_firefox_aurora_ua = parse(android_firefox_aurora_ua_string)
4850

4951

5052
class UserAgentsTest(unittest.TestCase):
@@ -90,6 +92,7 @@ def test_is_tablet_property(self):
9092
self.assertTrue(playbook_ua.is_tablet)
9193
self.assertTrue(kindle_fire_ua.is_tablet)
9294
self.assertTrue(nexus_7_ua.is_tablet)
95+
self.assertFalse(android_firefox_aurora_ua.is_tablet)
9396

9497
def test_is_mobile_property(self):
9598
self.assertTrue(iphone_ua.is_mobile)
@@ -110,6 +113,7 @@ def test_is_mobile_property(self):
110113
self.assertFalse(windows_ie_ua.is_mobile)
111114
self.assertFalse(ubuntu_firefox_ua.is_mobile)
112115
self.assertFalse(google_bot_ua.is_mobile)
116+
self.assertTrue(android_firefox_aurora_ua.is_mobile)
113117

114118
def test_is_touch_property(self):
115119
self.assertTrue(iphone_ua.is_touch_capable)
@@ -130,6 +134,7 @@ def test_is_touch_property(self):
130134
self.assertFalse(ubuntu_firefox_ua.is_touch_capable)
131135
self.assertFalse(google_bot_ua.is_touch_capable)
132136
self.assertFalse(nokia_n97_ua.is_touch_capable)
137+
self.assertTrue(android_firefox_aurora_ua.is_touch_capable)
133138

134139
def test_is_pc(self):
135140
self.assertFalse(iphone_ua.is_pc)
@@ -150,6 +155,7 @@ def test_is_pc(self):
150155
self.assertTrue(ubuntu_firefox_ua.is_pc)
151156
self.assertTrue(ie_touch_ua.is_pc)
152157
self.assertTrue(ie_ua.is_pc)
158+
self.assertFalse(android_firefox_aurora_ua.is_pc)
153159

154160
def test_is_bot(self):
155161
self.assertTrue(google_bot_ua.is_bot)
@@ -170,3 +176,4 @@ def test_is_bot(self):
170176
self.assertFalse(ie_touch_ua.is_bot)
171177
self.assertFalse(ie_ua.is_bot)
172178
self.assertFalse(nokia_n97_ua.is_bot)
179+
self.assertFalse(android_firefox_aurora_ua.is_bot)

0 commit comments

Comments
 (0)