From 6c086ff8b6432bea6f745303c4cf582e9a6ce269 Mon Sep 17 00:00:00 2001 From: Looly Date: Fri, 21 Jun 2024 11:43:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DMac=E4=B8=8B=E7=9A=84?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=B5=8F=E8=A7=88=E5=99=A8=E8=A2=AB=E8=AF=86?= =?UTF-8?q?=E5=88=AB=E4=B8=BA=E7=A7=BB=E5=8A=A8=E7=AB=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 ++- .../main/java/cn/hutool/http/useragent/OS.java | 10 ++++++++++ .../cn/hutool/http/useragent/UserAgentParser.java | 8 +++++++- .../hutool/http/useragent/UserAgentUtilTest.java | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60e2764a2..0ed5fccea 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/hutool-http/src/main/java/cn/hutool/http/useragent/OS.java b/hutool-http/src/main/java/cn/hutool/http/useragent/OS.java index 965d851d3..38a956c58 100755 --- a/hutool-http/src/main/java/cn/hutool/http/useragent/OS.java +++ b/hutool-http/src/main/java/cn/hutool/http/useragent/OS.java @@ -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()); + } } diff --git a/hutool-http/src/main/java/cn/hutool/http/useragent/UserAgentParser.java b/hutool-http/src/main/java/cn/hutool/http/useragent/UserAgentParser.java index d0f2a7fc3..476ec42b3 100644 --- a/hutool-http/src/main/java/cn/hutool/http/useragent/UserAgentParser.java +++ b/hutool-http/src/main/java/cn/hutool/http/useragent/UserAgentParser.java @@ -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; diff --git a/hutool-http/src/test/java/cn/hutool/http/useragent/UserAgentUtilTest.java b/hutool-http/src/test/java/cn/hutool/http/useragent/UserAgentUtilTest.java index 42142a73b..cc2814477 100644 --- a/hutool-http/src/test/java/cn/hutool/http/useragent/UserAgentUtilTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/useragent/UserAgentUtilTest.java @@ -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()); + } }