You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The IPAddress gem abuses the Enumerable mixin. One example is the each method. That method will always yield at least one value, which causes problems for other Ruby code that assumes an Enumerable cannot contain itself. For example, the following snippet will trigger a stack overflow:
The best solution would be to draw a distinction between an address and a network, like Python3's ipaddress module. If that were the case, then IPNetwork#each would yield a bunch of IPAddress objects, which would not implement #each.
A smaller change that wouldn't break compatibility with existing IPAddress users to be to define an as_json method which would simply call to_string.
The text was updated successfully, but these errors were encountered:
asomers
added a commit
to asomers/ipaddress
that referenced
this issue
Aug 7, 2017
Add IPAddress::IPv4#as_json and IPAddress::IPv6#as_json. If that method
is not defined, then ActiveSupport will create it automatically, but it
overflows the stack due to the way that ipaddress uses #each.
Fixesipaddress-gem#89
Add IPAddress::IPv4#as_json and IPAddress::IPv6#as_json. If that method
is not defined, then ActiveSupport will create it automatically, but it
overflows the stack due to the way that ipaddress uses #each.
Fixesipaddress-gem#89
The IPAddress gem abuses the Enumerable mixin. One example is the
each
method. That method will always yield at least one value, which causes problems for other Ruby code that assumes an Enumerable cannot contain itself. For example, the following snippet will trigger a stack overflow:The best solution would be to draw a distinction between an address and a network, like Python3's ipaddress module. If that were the case, then
IPNetwork#each
would yield a bunch ofIPAddress
objects, which would not implement#each
.A smaller change that wouldn't break compatibility with existing IPAddress users to be to define an
as_json
method which would simply callto_string
.The text was updated successfully, but these errors were encountered: