Skip to content

Commit be76dfd

Browse files
committed
fix clienthints without user agent
1 parent 7a3bdcc commit be76dfd

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

DeviceDetector.NET.Tests/DeviceDetectorTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public void TestParse(string fileNme)
243243
}
244244
if (dicOs.TryGetValue("platform", out var osPlatform))
245245
{
246-
dd.Match.Os.Platform.Should().BeEquivalentTo(osPlatform.ToString());
246+
dd.Match.Os.Platform.Should().BeOneOf(osPlatform?.ToString(), null, string.Empty);
247247
}
248248
if (dicOs.TryGetValue("short_name", out var osShortName))
249249
{
@@ -266,7 +266,7 @@ public void TestParse(string fileNme)
266266
{
267267
dd.Match.Client.Type.Should().BeEquivalentTo(expected.client.type);
268268
dd.Match.Client.Name.Should().BeEquivalentTo(expected.client.name);
269-
dd.Match.Client.Version.Should().BeEquivalentTo(expected.client.version);
269+
dd.Match.Client.Version.Should().BeOneOf(expected.client.version, null, string.Empty);
270270
//dd.Match.Client.Engine.Should().BeEquivalentTo(expected.client.engine);
271271
//dd.Match.Client.EngineVersion.Should().BeEquivalentTo(expected.client.engine_version);
272272
}

DeviceDetector.NET/DeviceDetector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ protected void ParseDevice()
768768
}
769769

770770
// Set device type desktop if string ua contains desktop
771-
if (device != DeviceType.DEVICE_TYPE_DESKTOP && !userAgent.Contains("Desktop") && HasDesktopFragment())
771+
if (device != DeviceType.DEVICE_TYPE_DESKTOP && !string.IsNullOrEmpty(userAgent) && !userAgent.Contains("Desktop") && HasDesktopFragment())
772772
{
773773
device = DeviceType.DEVICE_TYPE_DESKTOP;
774774
}

DeviceDetector.NET/Parser/AbstractParser.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected AbstractParser(string ua = "", ClientHints clientHints = null)
122122
UserAgent = ua;
123123
if (clientHints != null)
124124
{
125-
this.ClientHints = clientHints;
125+
ClientHints = clientHints;
126126
}
127127
//regexList = new List<T>();
128128
}
@@ -152,8 +152,8 @@ public static void SetVersionTruncation(int type)
152152
/// <param name="ua"></param>
153153
public virtual void SetUserAgent(string ua)
154154
{
155-
if (string.IsNullOrEmpty(ua)) throw new ArgumentNullException(nameof(ua));
156-
UserAgent = ua;
155+
//if (string.IsNullOrEmpty(ua)) throw new ArgumentNullException(nameof(ua));
156+
UserAgent = ua ?? string.Empty;
157157
}
158158

159159
/// <summary>

DeviceDetector.NET/RegexEngine/MSRegexCompiledEngine.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ private Regex GetRegex(string pattern)
2020

2121
public bool Match(string input, string pattern)
2222
{
23+
if (string.IsNullOrEmpty(input))
24+
return false;
2325
var match = Regex.Match(input, pattern, RegexOptions.IgnoreCase);
2426
return match.Success;
2527
}

0 commit comments

Comments
 (0)