Skip to content

Commit

Permalink
Fix: documentation and add unit test issue 294 (#300)
Browse files Browse the repository at this point in the history
* Fix: documentation and add unit test issue 294

* Fix: the issue 294 bug

* Update securitycodescan.yml
  • Loading branch information
lduchosal authored Jan 18, 2024
1 parent fab8751 commit 8155032
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/securitycodescan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ on:
branches: [ "master" ]
schedule:
- cron: '35 15 * * 1'


env:
DOTNET_ROLL_FORWARD: Major

jobs:
SCS:
runs-on: windows-latest
Expand Down
11 changes: 11 additions & 0 deletions src/System.Net.IPNetwork/IPNetwork2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
23 changes: 22 additions & 1 deletion src/System.Net.IPNetwork/IPNetworkCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace System.Net
using System.Collections.Generic;
using System.Numerics;

/// <summary>
/// A collection of IPNetwork2
/// </summary>
public class IPNetworkCollection : IEnumerable<IPNetwork2>, IEnumerator<IPNetwork2>
{
private BigInteger _enumerator;
Expand Down Expand Up @@ -59,6 +62,9 @@ private BigInteger _network

#region Count, Array, Enumerator

/// <summary>
/// Count the nnumber of IPAddresses in a IPNetworkCollection
/// </summary>
public BigInteger Count
{
get
Expand Down Expand Up @@ -102,6 +108,9 @@ IEnumerator IEnumerable.GetEnumerator()

#region IEnumerator<IPNetwork> Members

/// <summary>
/// Gets the current IEnumerator item
/// </summary>
public IPNetwork2 Current
{
get { return this[this._enumerator]; }
Expand All @@ -111,6 +120,9 @@ public IPNetwork2 Current

#region IDisposable Members

/// <summary>
/// Dispose the IPNetwork instance
/// </summary>
public void Dispose()
{
// nothing to dispose
Expand All @@ -120,12 +132,18 @@ public void Dispose()
#endregion

#region IEnumerator Members

/// <summary>
/// Gets the element in the collection at the current position of the enumerator.
/// </summary>
object IEnumerator.Current
{
get { return this.Current; }
}

/// <summary>
/// Advances the enumerator to the next element of the collection.
/// </summary>
/// <returns>true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection.</returns>
public bool MoveNext()
{
this._enumerator++;
Expand All @@ -137,6 +155,9 @@ public bool MoveNext()
return true;
}

/// <summary>
/// Sets the enumerator to its initial position, which is before the first element in the collection.
/// </summary>
public void Reset()
{
this._enumerator = -1;
Expand Down
10 changes: 10 additions & 0 deletions src/TestProject/TryParseUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = IPNetwork2.TryParse("*", out IPNetwork2 ipaddress1);
Assert.AreEqual(false, result, "parsed1");
}
#endregion
}
}

0 comments on commit 8155032

Please sign in to comment.