Skip to content
This repository has been archived by the owner on Jan 31, 2018. It is now read-only.

Commit

Permalink
Merge pull request #632 from willkg/1192812-browser
Browse files Browse the repository at this point in the history
[bug 1192812] Add support for Firefox for iOS user agents
  • Loading branch information
willkg committed Aug 10, 2015
2 parents cd2bef6 + 22b0604 commit b71124a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
16 changes: 12 additions & 4 deletions fjord/base/browsers.py
Expand Up @@ -66,11 +66,11 @@ def parse_ua(ua):
no_browser = Browser(UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
mobile or None)

if 'firefox' not in ua.lower():
# Firefox browsers have either "Firefox" or "FxiOS" in the UA.
if 'firefox' not in ua.lower() and 'fxios' not in ua.lower():
return no_browser

# For reference, a normal Firefox on android user agent looks like
# Mozilla/5.0 (Android; Mobile; rv:14.0) Gecko/14.0 Firefox/14.0.2
# See fjord/base/tests/user_agent_data.json for valid user agents.

# Extract the part within the parenthesis, and the part after the
# parenthesis. Inside has information about the platform, and
Expand Down Expand Up @@ -98,11 +98,14 @@ def parse_ua(ua):
browser_version = part[1]
elif 'Iceweasel' in part:
browser = 'Iceweasel'
elif 'FxiOS' in part:
browser = 'Firefox for iOS'
browser_version = part[1]

platform = platform_parts.pop(0)
platform_version = UNKNOWN

while platform in ['X11', 'Ubuntu', 'U']:
while platform in ['X11', 'Ubuntu', 'U', 'iPad', 'iPhone']:
platform = platform_parts.pop(0)

if platform == 'Windows':
Expand All @@ -120,6 +123,11 @@ def parse_ua(ua):
platform = 'Linux'
elif platform.startswith('FreeBSD'):
platform = 'FreeBSD'
elif platform.startswith('CPU iPhone'):
# Looks like "CPU iPhone OS 8_3 like Mac OS X" and we want
# the "8_3" part. Then we switch it to "8.3"
platform_version = platform.split(' ')[3].replace('_', '.')
platform = 'iPhone OS'
elif platform in ('OS X', 'Macintosh'):
for part in platform_parts:
if 'OS X' in part:
Expand Down
16 changes: 16 additions & 0 deletions fjord/base/tests/user_agent_data.json
Expand Up @@ -174,5 +174,21 @@
"platform": "Windows",
"platform_version": "XP",
"mobile": false
},
{
"user_agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4",
"browser": "Firefox for iOS",
"browser_version": "1.0",
"platform": "iPhone OS",
"platform_version": "8.3",
"mobile": true
},
{
"user_agent": "Mozilla/5.0 (iPad; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) FxiOS/1.0 Mobile/12F69 Safari/600.1.4",
"browser": "Firefox for iOS",
"browser_version": "1.0",
"platform": "iPhone OS",
"platform_version": "8.3",
"mobile": true
}
]

0 comments on commit b71124a

Please sign in to comment.