mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-02-05 08:42:50 +03:00
Fix negated IP addresses without subnet mask not being parsed correctly (#13854)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user