diff --git a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs index 7b6d456..842e4ff 100644 --- a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs +++ b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs @@ -75,7 +75,8 @@ public static class HttpUserAgentStatics /// /// Creates default browser mapping regex /// - private static Regex CreateDefaultBrowserRegex(string key) => new($@"{key}.*?([0-9\.]+)", DefaultBrowserRegexFlags); + private static Regex CreateDefaultBrowserRegex(string key) + => new($@"{key}.*?([0-9\.]+)", DefaultBrowserRegexFlags); /// /// Browsers @@ -253,7 +254,8 @@ public static readonly (string Key, string Value)[] Robots = ( "SemrushBot", "SEMRush"), ( "SEOkicks", "SEOkicks"), ( "seoscanners.net", "SEO Scanners"), - ( "Sistrix", "Sistrix" ) + ( "Sistrix", "Sistrix" ), + ( "WhatsApp", "WhatsApp" ) ]; /// diff --git a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentType.cs b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentType.cs index f0fe8f9..6bddba2 100644 --- a/src/MyCSharp.HttpUserAgentParser/HttpUserAgentType.cs +++ b/src/MyCSharp.HttpUserAgentParser/HttpUserAgentType.cs @@ -18,5 +18,5 @@ public enum HttpUserAgentType : byte /// /// Robot /// - Robot, + Robot } diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs index c392ee7..e626672 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs @@ -12,6 +12,9 @@ public class HttpUserAgentInformationExtensionsTests [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 Edg/90.0.818.62", HttpUserAgentType.Browser, false)] [InlineData("Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML,like Gecko) Version/9.0 Mobile/13B143 Safari/601.1 (compatible; AdsBot-Google-Mobile; +http://www.google.com/mobile/adsbot.html)", HttpUserAgentType.Robot, false)] [InlineData("APIs-Google (+https://developers.google.com/webmasters/APIs-Google.html)", HttpUserAgentType.Robot, false)] + [InlineData("WhatsApp/2.22.20.72 A", HttpUserAgentType.Robot, false)] + [InlineData("WhatsApp/2.22.19.78 I", HttpUserAgentType.Robot, false)] + [InlineData("WhatsApp/2.2236.3 N", HttpUserAgentType.Robot, false)] [InlineData("Invalid user agent", HttpUserAgentType.Unknown, false)] public void IsType(string userAgent, HttpUserAgentType expectedType, bool isMobile) { diff --git a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs index dbb952a..2e245be 100644 --- a/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs +++ b/tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs @@ -54,7 +54,6 @@ public class HttpUserAgentParserTests [InlineData("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.107", "Opera", "76.0.4017.107", "Windows 10", HttpUserAgentPlatformType.Windows, null)] [InlineData("Mozilla/5.0 (Macintosh; Intel Mac OS X 11_3_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.107", "Opera", "76.0.4017.107", "Mac OS X", HttpUserAgentPlatformType.MacOS, null)] [InlineData("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 OPR/76.0.4017.107", "Opera", "76.0.4017.107", "Linux", HttpUserAgentPlatformType.Linux, null)] - [InlineData("Mozilla/5.0 (Linux; Android 10; VOG-L29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.210 Mobile Safari/537.36 OPR/63.0.3216.58473", "Opera", "63.0.3216.58473", "Android", HttpUserAgentPlatformType.Android, "Android")] public void BrowserTests(string ua, string name, string version, string platformName, HttpUserAgentPlatformType platformType, string? mobileDeviceType) { HttpUserAgentInformation uaInfo = HttpUserAgentInformation.Parse(ua); @@ -131,6 +130,9 @@ public void BrowserTests(string ua, string name, string version, string platform [InlineData("Mozilla/5.0 (compatible; adscanner/)", "AdScanner")] [InlineData("Mozilla/5.0 (compatible; SISTRIX Crawler; http://crawler.sistrix.net/)", "Sistrix")] [InlineData("Mozilla/5.0 (Linux; Android 7.0;) AppleWebKit/537.36 (KHTML, like Gecko) Mobile Safari/537.36 (compatible; PetalBot;+https://aspiegel.com/petalbot)", "PetalBot")] + [InlineData("WhatsApp/2.22.20.72 A", "WhatsApp")] + [InlineData("WhatsApp/2.22.19.78 I", "WhatsApp")] + [InlineData("WhatsApp/2.2236.3 N", "WhatsApp")] public void BotTests(string ua, string name) { HttpUserAgentInformation uaInfo = HttpUserAgentInformation.Parse(ua);