diff --git a/src/NzbDrone.Common.Test/Http/UserAgentParserFixture.cs b/src/NzbDrone.Common.Test/Http/UserAgentParserFixture.cs new file mode 100644 index 000000000..e262a1466 --- /dev/null +++ b/src/NzbDrone.Common.Test/Http/UserAgentParserFixture.cs @@ -0,0 +1,24 @@ +using FluentAssertions; +using NUnit.Framework; +using NzbDrone.Common.Http; +using NzbDrone.Test.Common; + +namespace NzbDrone.Common.Test.Http +{ + [TestFixture] + public class UserAgentParserFixture : TestBase + { + // Ref *Arr `_userAgent = $"{BuildInfo.AppName}/{BuildInfo.Version} ({osName} {osVersion})";` + // Ref Mylar `Mylar3/' +str(hash) +'(' +vers +') +http://www.github.com/mylar3/mylar3/` + [TestCase("Mylar3/ 3ee23rh23irqfq (13123123) http://www.github.com/mylar3/mylar3/", "Mylar3")] + [TestCase("Lidarr/1.0.0.2300 (ubuntu 20.04)", "Lidarr")] + [TestCase("Radarr/1.0.0.2300 (ubuntu 20.04)", "Radarr")] + [TestCase("Readarr/1.0.0.2300 (ubuntu 20.04)", "Readarr")] + [TestCase("Sonarr/3.0.6.9999 (ubuntu 20.04)", "Sonarr")] + [TestCase("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36", "Other")] + public void should_parse_user_agent(string userAgent, string parsedAgent) + { + UserAgentParser.ParseSource(userAgent).Should().Be(parsedAgent); + } + } +} diff --git a/src/NzbDrone.Common/Http/UserAgentParser.cs b/src/NzbDrone.Common/Http/UserAgentParser.cs index e1164b9e8..8eb5f6d6a 100644 --- a/src/NzbDrone.Common/Http/UserAgentParser.cs +++ b/src/NzbDrone.Common/Http/UserAgentParser.cs @@ -9,7 +9,7 @@ namespace NzbDrone.Common.Http { public static class UserAgentParser { - private static readonly Regex AppSourceRegex = new Regex(@"(?.*)\/.*(\(.*\))?", + private static readonly Regex AppSourceRegex = new Regex(@"(?[a-z0-9]*)\/.*(?:\(.*\))?", RegexOptions.IgnoreCase | RegexOptions.Compiled); public static string SimplifyUserAgent(string userAgent)