From dd99e5f1b70240255e7fc0c04383ab21029c391d Mon Sep 17 00:00:00 2001 From: lduchosal Date: Thu, 18 Jan 2024 08:39:43 +0100 Subject: [PATCH 1/3] Fix: documentation and add unit test issue 294 --- .../IPNetworkCollection.cs | 23 ++++++++++++++++++- src/TestProject/TryParseUnitTest.cs | 10 ++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/System.Net.IPNetwork/IPNetworkCollection.cs b/src/System.Net.IPNetwork/IPNetworkCollection.cs index ea9f570..e694832 100644 --- a/src/System.Net.IPNetwork/IPNetworkCollection.cs +++ b/src/System.Net.IPNetwork/IPNetworkCollection.cs @@ -8,6 +8,9 @@ namespace System.Net using System.Collections.Generic; using System.Numerics; + /// + /// A collection of IPNetwork2 + /// public class IPNetworkCollection : IEnumerable, IEnumerator { private BigInteger _enumerator; @@ -59,6 +62,9 @@ private BigInteger _network #region Count, Array, Enumerator + /// + /// Count the nnumber of IPAddresses in a IPNetworkCollection + /// public BigInteger Count { get @@ -102,6 +108,9 @@ IEnumerator IEnumerable.GetEnumerator() #region IEnumerator Members + /// + /// Gets the current IEnumerator item + /// public IPNetwork2 Current { get { return this[this._enumerator]; } @@ -111,6 +120,9 @@ public IPNetwork2 Current #region IDisposable Members + /// + /// Dispose the IPNetwork instance + /// public void Dispose() { // nothing to dispose @@ -120,12 +132,18 @@ public void Dispose() #endregion #region IEnumerator Members - + /// + /// Gets the element in the collection at the current position of the enumerator. + /// object IEnumerator.Current { get { return this.Current; } } + /// + /// Advances the enumerator to the next element of the collection. + /// + /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection. public bool MoveNext() { this._enumerator++; @@ -137,6 +155,9 @@ public bool MoveNext() return true; } + /// + /// Sets the enumerator to its initial position, which is before the first element in the collection. + /// public void Reset() { this._enumerator = -1; diff --git a/src/TestProject/TryParseUnitTest.cs b/src/TestProject/TryParseUnitTest.cs index f7d5772..c394695 100644 --- a/src/TestProject/TryParseUnitTest.cs +++ b/src/TestProject/TryParseUnitTest.cs @@ -333,5 +333,15 @@ public void Test_IPAddress_TryParse(string ipaddress, bool parsed) } #endregion + + #region Issue294 + + [TestMethod] + public void Test_IPNetwork_TryParse_Issue294() + { + bool result = IPNetwork.TryParse("*", out IPNetwork ipaddress1); + Assert.AreEqual(false, result, "parsed1"); + } + #endregion } } From fa2d5647f3a409db384719f2cd9059fba694c0e4 Mon Sep 17 00:00:00 2001 From: lduchosal Date: Thu, 18 Jan 2024 10:36:41 +0100 Subject: [PATCH 2/3] Fix: the issue 294 bug --- src/System.Net.IPNetwork/IPNetwork2.cs | 11 +++++++++++ src/TestProject/TryParseUnitTest.cs | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/System.Net.IPNetwork/IPNetwork2.cs b/src/System.Net.IPNetwork/IPNetwork2.cs index e1b8854..9e5b867 100644 --- a/src/System.Net.IPNetwork/IPNetwork2.cs +++ b/src/System.Net.IPNetwork/IPNetwork2.cs @@ -624,6 +624,17 @@ private static void InternalParse(bool tryParse, string network, ICidrGuess cidr string[] args = network.Split(new char[] { ' ', '/' }, splitOptions); byte cidr = 0; + if (args.Length == 0) + { + if (tryParse == false) + { + throw new ArgumentNullException("network"); + } + + ipnetwork = null; + return; + } + if (args.Length == 1) { string cidrlessNetwork = args[0]; diff --git a/src/TestProject/TryParseUnitTest.cs b/src/TestProject/TryParseUnitTest.cs index c394695..77a2595 100644 --- a/src/TestProject/TryParseUnitTest.cs +++ b/src/TestProject/TryParseUnitTest.cs @@ -339,7 +339,7 @@ public void Test_IPAddress_TryParse(string ipaddress, bool parsed) [TestMethod] public void Test_IPNetwork_TryParse_Issue294() { - bool result = IPNetwork.TryParse("*", out IPNetwork ipaddress1); + bool result = IPNetwork2.TryParse("*", out IPNetwork2 ipaddress1); Assert.AreEqual(false, result, "parsed1"); } #endregion From f9685cac44d0620143220b22a5b6f9ae4a19d7c0 Mon Sep 17 00:00:00 2001 From: lduchosal Date: Thu, 18 Jan 2024 10:57:34 +0100 Subject: [PATCH 3/3] Update securitycodescan.yml --- .github/workflows/securitycodescan.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/securitycodescan.yml b/.github/workflows/securitycodescan.yml index 37b1e71..76f089f 100644 --- a/.github/workflows/securitycodescan.yml +++ b/.github/workflows/securitycodescan.yml @@ -16,7 +16,10 @@ on: branches: [ "master" ] schedule: - cron: '35 15 * * 1' - + +env: + DOTNET_ROLL_FORWARD: Major + jobs: SCS: runs-on: windows-latest