修复Mac下的微信浏览器被识别为移动端问题

This commit is contained in:
Looly 2024-06-21 11:43:07 +08:00
parent d934831676
commit 6c086ff8b6
4 changed files with 34 additions and 2 deletions

View File

@ -2,7 +2,7 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.29(2024-06-18)
# 5.8.29(2024-06-21)
### 🐣新特性
* 【core 】 DateUtil增加offsetYear方法
@ -22,6 +22,7 @@
* 【core 】 修复DateUtil.offset空指针问题issue#3617@Github
* 【core 】 修复PathMover.moveContent问题issue#IA5Q8D@Gitee
* 【db 】 修复PooledConnection可能的数据库驱动未找到问题issue#IA6EUQ@Gitee
* 【http 】 修复Mac下的微信浏览器被识别为移动端问题issue#IA74K2@Gitee
-------------------------------------------------------------------------------------------------------------
# 5.8.28(2024-05-29)

View File

@ -104,4 +104,14 @@ public class OS extends UserAgentInfo {
}
return ReUtil.getGroup1(this.versionPattern, userAgentString);
}
/**
* 是否为MacOS
*
* @return 是否为MacOS
* @since 5.8.29
*/
public boolean isMacOS(){
return "OSX".equals(getName());
}
}

View File

@ -40,7 +40,13 @@ public class UserAgentParser {
// 平台
final Platform platform = parsePlatform(userAgentString);
userAgent.setPlatform(platform);
userAgent.setMobile(platform.isMobile() || browser.isMobile());
// issue#IA74K2 MACOS下的微信不属于移动平台
if(platform.isMobile() || browser.isMobile()){
if(false == os.isMacOS()){
userAgent.setMobile(true);
}
}
return userAgent;

View File

@ -488,4 +488,19 @@ public class UserAgentUtilTest {
Assert.assertEquals("Windows", ua2.getPlatform().toString());
Assert.assertFalse(ua2.isMobile());
}
@Test
public void issueIA74K2Test() {
UserAgent ua = UserAgentUtil.parse(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) MicroMessenger/6.8.0(0x16080000) MacWechat/3.8.7(0x13080710) Safari/605.1.15 NetType/WIFI");
Assert.assertEquals("MicroMessenger", ua.getBrowser().toString());
Assert.assertEquals("6.8.0", ua.getVersion());
Assert.assertEquals("Webkit", ua.getEngine().toString());
Assert.assertEquals("605.1.15", ua.getEngineVersion());
Assert.assertEquals("OSX", ua.getOs().toString());
Assert.assertEquals("10_15_7", ua.getOsVersion());
Assert.assertEquals("Mac", ua.getPlatform().toString());
Assert.assertFalse(ua.isMobile());
}
}