From 6357737978ad9d59a1311ecf1ef94cf97371014d Mon Sep 17 00:00:00 2001 From: Umair Khan Date: Thu, 22 Jun 2017 09:34:26 +0500 Subject: [PATCH] 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/ --- zerver/signals.py | 4 ++-- zerver/tests/test_new_users.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/zerver/signals.py b/zerver/signals.py index e6f92ac3c3..f7e462ef2e 100644 --- a/zerver/signals.py +++ b/zerver/signals.py @@ -15,6 +15,8 @@ def get_device_browser(user_agent): user_agent = user_agent.lower() if "edge" in user_agent: 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: return 'Chrome' 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" elif "safari" in user_agent and "chrome" not in user_agent and "chromium" not in user_agent: return "Safari" - elif "opera" in user_agent: - return "Opera" elif "msie" in user_agent or "trident" in user_agent: return "Internet Explorer" elif "zulip" in user_agent: diff --git a/zerver/tests/test_new_users.py b/zerver/tests/test_new_users.py index 589b81ad9e..e5d3f8e766 100644 --- a/zerver/tests/test_new_users.py +++ b/zerver/tests/test_new_users.py @@ -89,6 +89,9 @@ class TestBrowserAndOsUserAgentStrings(ZulipTestCase): 'Version/10.0.2 Safari/602.3.12', 'Safari', 'MacOS'), ('ZulipAndroid/1.0', 'Zulip', 'Android'), ('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/' ' (KHTML, like Gecko) Chrome/ Safari' '/ Edge/.'