damballa / inet.data

Clojure library for modeling various Internet-related conceptual entities as data
Eclipse Public License 1.0
38 stars 6 forks source link

Unexpected behaviour with network-contains? #2

Open danielcompton opened 9 years ago

danielcompton commented 9 years ago

It seems like network-contains? doesn't validate that it's comparing networks, and will compare arbitrary strings. Is this intended?

(ip/network-contains? "abx-@" "abx-@")
=> true
llasram commented 9 years ago

Yes -- it's an unfortunate side-effect of design decisions made elsewhere. Pervasively inet.data treats malformed data as a non-exceptional condition, returning nil on representation-parsing errors instead of throwing an exception. The library uses protocols to allow direct use of alternative representations in functions like network-contains?. This latter decision makes it convenient to use alternative compatible objects (like standard library InetAddress instances), and leads to compact-reading examples when using string representations; but it also leads to a number of bad/unexpected interactions like the one here, and was probably a mistake overall.

I'm open to improvements to the basic design, but fear it would be fairly extensive -- something along the lines of (a) distinguishing direct vs indirect representations, (b) introducing new functions which coerce as-necessary to a direct representation, throwing an exception if they fail, and (c) updating the library to pervasively use those functions.