Skip to content

Commit 56daa6b

Browse files
authored
add whatsapp as robot (#48)
* add whatsapp as robot * remove test code * add using
1 parent 20c6f95 commit 56daa6b

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public static class HttpUserAgentStatics
7575
/// <summary>
7676
/// Creates default browser mapping regex
7777
/// </summary>
78-
private static Regex CreateDefaultBrowserRegex(string key) => new($@"{key}.*?([0-9\.]+)", DefaultBrowserRegexFlags);
78+
private static Regex CreateDefaultBrowserRegex(string key)
79+
=> new($@"{key}.*?([0-9\.]+)", DefaultBrowserRegexFlags);
7980

8081
/// <summary>
8182
/// Browsers
@@ -253,7 +254,8 @@ public static readonly (string Key, string Value)[] Robots =
253254
( "SemrushBot", "SEMRush"),
254255
( "SEOkicks", "SEOkicks"),
255256
( "seoscanners.net", "SEO Scanners"),
256-
( "Sistrix", "Sistrix" )
257+
( "Sistrix", "Sistrix" ),
258+
( "WhatsApp", "WhatsApp" )
257259
];
258260

259261
/// <summary>

src/MyCSharp.HttpUserAgentParser/HttpUserAgentType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ public enum HttpUserAgentType : byte
1818
/// <summary>
1919
/// Robot
2020
/// </summary>
21-
Robot,
21+
Robot
2222
}

tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentInformationExtensionsTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ public class HttpUserAgentInformationExtensionsTests
1212
[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)]
1313
[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)]
1414
[InlineData("APIs-Google (+https://developers.google.com/webmasters/APIs-Google.html)", HttpUserAgentType.Robot, false)]
15+
[InlineData("WhatsApp/2.22.20.72 A", HttpUserAgentType.Robot, false)]
16+
[InlineData("WhatsApp/2.22.19.78 I", HttpUserAgentType.Robot, false)]
17+
[InlineData("WhatsApp/2.2236.3 N", HttpUserAgentType.Robot, false)]
1518
[InlineData("Invalid user agent", HttpUserAgentType.Unknown, false)]
1619
public void IsType(string userAgent, HttpUserAgentType expectedType, bool isMobile)
1720
{

tests/MyCSharp.HttpUserAgentParser.UnitTests/HttpUserAgentParserTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public class HttpUserAgentParserTests
5454
[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)]
5555
[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)]
5656
[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)]
57-
[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")]
5857
public void BrowserTests(string ua, string name, string version, string platformName, HttpUserAgentPlatformType platformType, string? mobileDeviceType)
5958
{
6059
HttpUserAgentInformation uaInfo = HttpUserAgentInformation.Parse(ua);
@@ -131,6 +130,9 @@ public void BrowserTests(string ua, string name, string version, string platform
131130
[InlineData("Mozilla/5.0 (compatible; adscanner/)", "AdScanner")]
132131
[InlineData("Mozilla/5.0 (compatible; SISTRIX Crawler; http://crawler.sistrix.net/)", "Sistrix")]
133132
[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")]
133+
[InlineData("WhatsApp/2.22.20.72 A", "WhatsApp")]
134+
[InlineData("WhatsApp/2.22.19.78 I", "WhatsApp")]
135+
[InlineData("WhatsApp/2.2236.3 N", "WhatsApp")]
134136
public void BotTests(string ua, string name)
135137
{
136138
HttpUserAgentInformation uaInfo = HttpUserAgentInformation.Parse(ua);

0 commit comments

Comments
 (0)