mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-05-24 02:02:29 -04:00
Fix negated IP addresses without subnet mask not being parsed correctly (#13854)
This commit is contained in:
parent
0bbc6bb31d
commit
c152f610ce
@ -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;
|
||||
}
|
||||
|
@ -79,7 +79,10 @@ namespace Jellyfin.Networking.Tests
|
||||
[InlineData("[fe80::7add:12ff:febb:c67b%16]")]
|
||||
[InlineData("fd23:184f:2029:0:3139:7386:67d7:d517/56")]
|
||||
public static void TryParseValidIPStringsTrue(string address)
|
||||
=> Assert.True(NetworkUtils.TryParseToSubnet(address, out _));
|
||||
{
|
||||
Assert.True(NetworkUtils.TryParseToSubnet(address, out _));
|
||||
Assert.True(NetworkUtils.TryParseToSubnet('!' + address, out _, true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks invalid IP address formats.
|
||||
|
Loading…
x
Reference in New Issue
Block a user