diff options
| author | Shadowghost <Ghost_of_Stone@web.de> | 2022-07-20 11:47:48 +0200 |
|---|---|---|
| committer | Shadowghost <Ghost_of_Stone@web.de> | 2022-07-20 11:47:48 +0200 |
| commit | a492082f4e015d6d38368c4ac05d39d236387214 (patch) | |
| tree | 97852d6e845ee6b876a083a06a0cbd1f2f5a364c | |
| parent | 2043a33f815d9a16aa819095e6310620ca4e72a2 (diff) | |
Apply review suggestions and fix build
| -rw-r--r-- | Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs | 5 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/IPData.cs | 17 | ||||
| -rw-r--r-- | MediaBrowser.Common/Net/NetworkExtensions.cs | 10 | ||||
| -rw-r--r-- | tests/Jellyfin.Server.Tests/ParseNetworkTests.cs | 8 |
4 files changed, 19 insertions, 21 deletions
diff --git a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs index 507395106..a393b80db 100644 --- a/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs +++ b/Jellyfin.Server/Extensions/ApiServiceCollectionExtensions.cs @@ -372,6 +372,11 @@ namespace Jellyfin.Server.Extensions return; } + if (addr.IsIPv4MappedToIPv6) + { + addr = addr.MapToIPv4(); + } + if (prefixLength == 32) { options.KnownProxies.Add(addr); diff --git a/MediaBrowser.Common/Net/IPData.cs b/MediaBrowser.Common/Net/IPData.cs index 3c6adc7e8..6901d6ad8 100644 --- a/MediaBrowser.Common/Net/IPData.cs +++ b/MediaBrowser.Common/Net/IPData.cs @@ -14,13 +14,12 @@ namespace MediaBrowser.Common.Net /// </summary> /// <param name="address">An <see cref="IPAddress"/>.</param> /// <param name="subnet">The <see cref="IPNetwork"/>.</param> - public IPData( - IPAddress address, - IPNetwork? subnet) + /// <param name="name">The object's name.</param> + public IPData(IPAddress address, IPNetwork? subnet, string name) { Address = address; Subnet = subnet ?? (address.AddressFamily == AddressFamily.InterNetwork ? new IPNetwork(address, 32) : new IPNetwork(address, 128)); - Name = string.Empty; + Name = name; } /// <summary> @@ -28,15 +27,9 @@ namespace MediaBrowser.Common.Net /// </summary> /// <param name="address">An <see cref="IPAddress"/>.</param> /// <param name="subnet">The <see cref="IPNetwork"/>.</param> - /// <param name="name">The object's name.</param> - public IPData( - IPAddress address, - IPNetwork? subnet, - string name) + public IPData(IPAddress address, IPNetwork? subnet) + : this(address, subnet, string.Empty) { - Address = address; - Subnet = subnet ?? (address.AddressFamily == AddressFamily.InterNetwork ? new IPNetwork(address, 32) : new IPNetwork(address, 128)); - Name = name; } /// <summary> diff --git a/MediaBrowser.Common/Net/NetworkExtensions.cs b/MediaBrowser.Common/Net/NetworkExtensions.cs index 4cba1c99f..ae1e47ccc 100644 --- a/MediaBrowser.Common/Net/NetworkExtensions.cs +++ b/MediaBrowser.Common/Net/NetworkExtensions.cs @@ -13,6 +13,10 @@ namespace MediaBrowser.Common.Net /// </summary> public static class NetworkExtensions { + // Use regular expression as CheckHostName isn't RFC5892 compliant. + // Modified from gSkinner's expression at https://stackoverflow.com/questions/11809631/fully-qualified-domain-name-validation + private static readonly Regex _fqdnRegex = new Regex(@"(?im)^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){0,127}(?![0-9]*$)[a-z0-9-]+\.?)(:(\d){1,5}){0,1}$"); + /// <summary> /// Returns true if the IPAddress contains an IP6 Local link address. /// </summary> @@ -227,12 +231,8 @@ namespace MediaBrowser.Common.Net if (hosts.Length <= 2) { - // Use regular expression as CheckHostName isn't RFC5892 compliant. - // Modified from gSkinner's expression at https://stackoverflow.com/questions/11809631/fully-qualified-domain-name-validation - string pattern = @"(?im)^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){0,127}(?![0-9]*$)[a-z0-9-]+\.?)(:(\d){1,5}){0,1}$"; - // Is hostname or hostname:port - if (Regex.IsMatch(hosts[0], pattern)) + if (_fqdnRegex.IsMatch(hosts[0])) { try { diff --git a/tests/Jellyfin.Server.Tests/ParseNetworkTests.cs b/tests/Jellyfin.Server.Tests/ParseNetworkTests.cs index a1bdfa31b..fc5f5f4c6 100644 --- a/tests/Jellyfin.Server.Tests/ParseNetworkTests.cs +++ b/tests/Jellyfin.Server.Tests/ParseNetworkTests.cs @@ -21,9 +21,9 @@ namespace Jellyfin.Server.Tests data.Add( true, true, - new string[] { "192.168.t", "127.0.0.1", "1234.1232.12.1234" }, - new IPAddress[] { IPAddress.Loopback.MapToIPv6() }, - Array.Empty<IPNetwork>()); + new string[] { "192.168.t", "127.0.0.1", "::1", "1234.1232.12.1234" }, + new IPAddress[] { IPAddress.Loopback, }, + new IPNetwork[] { new IPNetwork(IPAddress.IPv6Loopback, 128) }); data.Add( true, @@ -64,7 +64,7 @@ namespace Jellyfin.Server.Tests true, true, new string[] { "localhost" }, - new IPAddress[] { IPAddress.Loopback.MapToIPv6() }, + new IPAddress[] { IPAddress.Loopback }, new IPNetwork[] { new IPNetwork(IPAddress.IPv6Loopback, 128) }); return data; } |
