jsakamoto / ipaddressrange

.NET Class Library for range of IP address, both IPv4 and IPv6.
Mozilla Public License 2.0
368 stars 71 forks source link

invalid CIDR #7

Closed M-Zuber closed 9 years ago

M-Zuber commented 9 years ago

What is the desired action if someone passes in the following ipcidr: 128.139.251.57/3212?

The first Regex matches, but then an IndexOutOfRangeException is thrown when trying to build the BitMask. If we where to make the first Regex stricter, there would still be a problem as this string also passes the Regex for a netmask.

-as an aside: should it be considered to let the TryParse catch more than just FormatException?

jsakamoto commented 9 years ago

Thank you for your report.

You are right, TryPase should not throw any exceptions, and Parse should not throw any exceptions except FormatException.

So I fixed it at 8ddb11f, and publish new NuGet package ( https://www.nuget.org/packages/IPAddressRange/ ).

Thanks!

M-Zuber commented 9 years ago

What I meant in my question about TryParse was should the catch in TryParse be changed from:

catch(FormatException`)

to

catch
jsakamoto commented 9 years ago

Yea, that's right, but if fix only TryParse, Parse method keep throw IndexOutOfRange exception.

So, I deside fix Parse method ( more exactly, fix internal implements at constractor).

But, you mean, I should be prepare for happen to unexpected type of exception?

Well, I understand that I should implemet in TryParse catch all types of exception not only FormatException.

I'll consider it well. Let me have few days.