Repository: fnando/browser (Ruby)

Issue:
MicroMessenger on Android not detected
## Description

WeChat MicroMessenger on Android not detected.

## How to reproduce

```rb
browser1 = Browser.new("Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.10(0x17000a21) NetType/4G Language/zh_CN")
browser2 = Browser.new("Mozilla/5.0 (Linux; Android 7.1.2; Redmi 4X Build/N2G47H; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045131 Mobile Safari/537.36 MMWEBID/9286 MicroMessenger/7.0.13.1640(0x27000D37) Process/tools NetType/WIFI Language/zh_CN ABI/arm64 WeChat/arm64")
```

## What do you expect

```
"#{browser1.name} #{browser1.full_version}" => "MicroMessenger 7.0.10"
"#{browser2.name} #{browser2.full_version}" => "MicroMessenger 7.0.13.1640"
```

## What happened instead

```
"#{browser1.name} #{browser1.full_version}" => "MicroMessenger 7.0.10"
"#{browser2.name} #{browser2.full_version}" => "QQ Browser 6.2"
```

## Software:

- Rails version: 6.0.2.1
- Browser gem version: 4.0.0

## Full backtrace

```text
2.6.5 :001 > browser1 = Browser.new("Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.10(0x17000a21) NetType/4G Language/zh_CN")
 => #<Browser::MicroMessenger:0x00007fcab0531420 @ua="Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.10(0x17000a21) NetType/4G Language/zh_CN", @accept_language=[]>
2.6.5 :002 > "#{browser1.name} #{browser1.full_version}"
 => "MicroMessenger 7.0.10"
2.6.5 :003 >
2.6.5 :004 > browser2 = Browser.new("Mozilla/5.0 (Linux; Android 7.1.2; Redmi 4X Build/N2G47H; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045131 Mobile Safari/537.36 MMWEBID/9286 MicroMessenger/7.0.13.1640(0x27000D37) Process/tools NetType/WIFI Language/zh_CN ABI/arm64 WeChat/arm64")
 => #<Browser::QQ:0x00007fcab0564ca8 @ua="Mozilla/5.0 (Linux; Android 7.1.2; Redmi 4X Build/N2G47H; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045131 Mobile Safari/537.36 MMWEBID/9286 MicroMessenger/7.0.13.1640(0x27000D37) Process/tools NetType/WIFI Language/zh_CN ABI/arm64 WeChat/arm64", @accept_language=[]>
2.6.5 :005 > "#{browser2.name} #{browser2.full_version}"
 => "QQ Browser 6.2"
```


Discussion:
### Possible fixes

```diff
diff --git a/lib/browser/browser.rb b/lib/browser/browser.rb
index e9e0746..b9bfdc3 100644
--- a/lib/browser/browser.rb
+++ b/lib/browser/browser.rb
@@ -67,6 +67,7 @@ module Browser
       Instagram,            # must be placed before Chrome and Safari
       Snapchat,             # must be placed before Chrome and Safari
       Weibo,                # must be placed before Chrome and Safari
+      MicroMessenger,       # must be placed before QQ
       QQ,                   # must be placed before Chrome and Safari
       Alipay,               # must be placed before Chrome and Safari
       Electron,             # must be placed before Chrome and Safari
@@ -76,7 +77,6 @@ module Browser
       SamsungBrowser,       # must be placed before Chrome and Safari
       Chrome,
       Safari,
-      MicroMessenger,
       Generic
     ]
   end
```



Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 53593304..4ca0787f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
 - Add Samsung browser.
 - Add The Knowledge AI bot to the bot list.
 - Add Go HttpClient to the bot list.
+- Fix MicroMessenger detection on Android
 
 ## 4.0.0
 
diff --git a/lib/browser/browser.rb b/lib/browser/browser.rb
index e9e07468..b9bfdc38 100644
--- a/lib/browser/browser.rb
+++ b/lib/browser/browser.rb
@@ -67,6 +67,7 @@ def self.matchers
       Instagram,            # must be placed before Chrome and Safari
       Snapchat,             # must be placed before Chrome and Safari
       Weibo,                # must be placed before Chrome and Safari
+      MicroMessenger,       # must be placed before QQ
       QQ,                   # must be placed before Chrome and Safari
       Alipay,               # must be placed before Chrome and Safari
       Electron,             # must be placed before Chrome and Safari
@@ -76,7 +77,6 @@ def self.matchers
       SamsungBrowser,       # must be placed before Chrome and Safari
       Chrome,
       Safari,
-      MicroMessenger,
       Generic
     ]
   end


Test patch:
diff --git a/test/ua.yml b/test/ua.yml
index 56d46499..8ef89fff 100644
--- a/test/ua.yml
+++ b/test/ua.yml
@@ -81,7 +81,8 @@ KINDLE_FIRE_HD_MOBILE: "Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; KFTT Build/
 LUMIA800: "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; XBLWP7; ZuneWP7"
 MAC_OS: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15"
 MAC_OSX: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9"
-MICRO_MESSENGER: "Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13E238 MicroMessenger/6.3.15 NetType/3G+ Language/zh_CN"
+MICRO_MESSENGER_IOS: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.10(0x17000a21) NetType/4G Language/zh_CN"
+MICRO_MESSENGER_ANDROID: "Mozilla/5.0 (Linux; Android 7.1.2; Redmi 4X Build/N2G47H; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045131 Mobile Safari/537.36 MMWEBID/9286 MicroMessenger/7.0.13.1640(0x27000D37) Process/tools NetType/WIFI Language/zh_CN ABI/arm64 WeChat/arm64"
 MIDP: MIDP-2.0
 MOBILE_CHROME: "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3"
 MS_EDGE: "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0"
diff --git a/test/unit/micro_messenger_test.rb b/test/unit/micro_messenger_test.rb
index 26eb2cb4..8e0b695b 100644
--- a/test/unit/micro_messenger_test.rb
+++ b/test/unit/micro_messenger_test.rb
@@ -3,18 +3,33 @@
 require "test_helper"
 
 class MicroMessengerTest < Minitest::Test
-  test "detects micro messenger 6.3.15" do
-    browser = Browser.new(Browser["MICRO_MESSENGER"])
+  test "detects micro messenger 7.0.10 on iOS" do
+    browser = Browser.new(Browser["MICRO_MESSENGER_IOS"])
 
     assert browser.micro_messenger?
     assert browser.wechat?
-    assert_equal "6.3.15", browser.full_version
+    assert_equal "7.0.10", browser.full_version
     assert_equal "MicroMessenger", browser.name
     assert_equal :micro_messenger, browser.id
   end
 
-  test "detects version by range" do
-    browser = Browser.new(Browser["MICRO_MESSENGER"])
-    assert browser.wechat?(%w[>=6 <7])
+  test "detects version by range on iOS" do
+    browser = Browser.new(Browser["MICRO_MESSENGER_IOS"])
+    assert browser.wechat?(%w[>=7 <8])
+  end
+
+  test "detects micro messenger 7.0.13.1640 on Android" do
+    browser = Browser.new(Browser["MICRO_MESSENGER_ANDROID"])
+
+    assert browser.micro_messenger?
+    assert browser.wechat?
+    assert_equal "7.0.13.1640", browser.full_version
+    assert_equal "MicroMessenger", browser.name
+    assert_equal :micro_messenger, browser.id
+  end
+
+  test "detects version by range on Android" do
+    browser = Browser.new(Browser["MICRO_MESSENGER_ANDROID"])
+    assert browser.wechat?(%w[>=7 <8])
   end
 end