get_device_browser: Fix Opera detection.

Starting from version 15, Opera uses 'OPR/' in its user agent string.
We need to move Opera detection before Chrome detection because
Opera's user agent string satisfies Chrome conditions as well.
Ref: https://dev.opera.com/blog/opera-user-agent-strings-opera-15-and-beyond/
This commit is contained in:
Umair Khan 2017-06-22 09:34:26 +05:00 committed by Tim Abbott
parent 14402b0b97
commit 6357737978
2 changed files with 5 additions and 2 deletions

View File

@ -15,6 +15,8 @@ def get_device_browser(user_agent):
user_agent = user_agent.lower() user_agent = user_agent.lower()
if "edge" in user_agent: if "edge" in user_agent:
return "Edge" return "Edge"
elif "opera" in user_agent or "opr/" in user_agent:
return "Opera"
elif "chrome" in user_agent and "chromium" not in user_agent: elif "chrome" in user_agent and "chromium" not in user_agent:
return 'Chrome' return 'Chrome'
elif "firefox" in user_agent and "seamonkey" not in user_agent and "chrome" not in user_agent: elif "firefox" in user_agent and "seamonkey" not in user_agent and "chrome" not in user_agent:
@ -23,8 +25,6 @@ def get_device_browser(user_agent):
return "Chromium" return "Chromium"
elif "safari" in user_agent and "chrome" not in user_agent and "chromium" not in user_agent: elif "safari" in user_agent and "chrome" not in user_agent and "chromium" not in user_agent:
return "Safari" return "Safari"
elif "opera" in user_agent:
return "Opera"
elif "msie" in user_agent or "trident" in user_agent: elif "msie" in user_agent or "trident" in user_agent:
return "Internet Explorer" return "Internet Explorer"
elif "zulip" in user_agent: elif "zulip" in user_agent:

View File

@ -89,6 +89,9 @@ class TestBrowserAndOsUserAgentStrings(ZulipTestCase):
'Version/10.0.2 Safari/602.3.12', 'Safari', 'MacOS'), 'Version/10.0.2 Safari/602.3.12', 'Safari', 'MacOS'),
('ZulipAndroid/1.0', 'Zulip', 'Android'), ('ZulipAndroid/1.0', 'Zulip', 'Android'),
('ZulipMobile/1.0', 'Zulip', None), ('ZulipMobile/1.0', 'Zulip', None),
('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36 '
'OPR/15.0.1147.100', 'Opera', 'Windows'),
('Mozilla/5.0 (Windows NT 10.0; <64-bit tags>) AppleWebKit/' ('Mozilla/5.0 (Windows NT 10.0; <64-bit tags>) AppleWebKit/'
'<WebKit Rev> (KHTML, like Gecko) Chrome/<Chrome Rev> Safari' '<WebKit Rev> (KHTML, like Gecko) Chrome/<Chrome Rev> Safari'
'/<WebKit Rev> Edge/<EdgeHTML Rev>.' '/<WebKit Rev> Edge/<EdgeHTML Rev>.'