aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Common
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Common')
-rw-r--r--MediaBrowser.Common/Net/NetworkUtils.cs21
1 files changed, 16 insertions, 5 deletions
diff --git a/MediaBrowser.Common/Net/NetworkUtils.cs b/MediaBrowser.Common/Net/NetworkUtils.cs
index a498d6271..24ed47a81 100644
--- a/MediaBrowser.Common/Net/NetworkUtils.cs
+++ b/MediaBrowser.Common/Net/NetworkUtils.cs
@@ -198,14 +198,25 @@ public static partial class NetworkUtils
/// <returns><c>True</c> if parsing was successful.</returns>
public static bool TryParseToSubnet(ReadOnlySpan<char> value, [NotNullWhen(true)] out IPNetwork? result, bool negated = false)
{
+ // If multiple IP addresses are in a comma-separated string, the individual addresses may contain leading and/or trailing whitespace
value = value.Trim();
+
+ bool isAddressNegated = false;
+ if (value.StartsWith('!'))
+ {
+ isAddressNegated = true;
+ value = value[1..]; // Remove leading '!' character
+ }
+
+ if (isAddressNegated != negated)
+ {
+ result = null;
+ return false;
+ }
+
if (value.Contains('/'))
{
- if (negated && value.StartsWith("!") && IPNetwork.TryParse(value[1..], out result))
- {
- return true;
- }
- else if (!negated && IPNetwork.TryParse(value, out result))
+ if (IPNetwork.TryParse(value, out result))
{
return true;
}