Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add whatsapp as robot #48

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/MyCSharp.HttpUserAgentParser/HttpUserAgentStatics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public static class HttpUserAgentStatics
/// <summary>
/// Creates default browser mapping regex
/// </summary>
private static Regex CreateDefaultBrowserRegex(string key) => new($@"{key}.*?([0-9\.]+)", DefaultBrowserRegexFlags);
private static Regex CreateDefaultBrowserRegex(string key)
=> new($@"{key}.*?([0-9\.]+)", DefaultBrowserRegexFlags);

/// <summary>
/// Browsers
Expand Down Expand Up @@ -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" )
];

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/MyCSharp.HttpUserAgentParser/HttpUserAgentType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ public enum HttpUserAgentType : byte
/// <summary>
/// Robot
/// </summary>
Robot,
Robot
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down