Switch from ruby-ip to standard library ipaddr#39
Open
bquorning wants to merge 4 commits into
Open
Conversation
Replace the ruby-ip-specific IP#to_hex helper with a computation based on the integer address value, which produces an identical zero-padded 32-nibble lowercase hex string. This is a behavior-preserving refactor (verified equal for the values used here) that removes reliance on a ruby-ip-only method, paving the way for switching to the standard library ipaddr, which has no to_hex. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The ip4 and ip6 mechanisms both duplicate the check that flags a CIDR netblock whose address has bits set outside its network prefix. Move it into a single SPF::Util.ip_network_has_host_bits? predicate so the detection logic lives in one place. This is behavior-preserving; it also isolates the one piece of address math that must change when switching from ruby-ip (which exposes #offset) to ipaddr (which masks host bits away on construction), keeping that later switch a localized change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Derive the ip4 and ip6 mechanism's textual params from the parsed address string (@ip_address) rather than from the @ip_network object, and reuse #params when building the InvalidMechCIDRError message instead of interpolating @ip_network directly. Under ruby-ip these produce identical output, so this is behavior-preserving (verified for the ip4/ip6 rendering cases). It matters for the upcoming switch to ipaddr: ipaddr masks host bits away on construction (1.2.3.4/24 becomes 1.2.3.0/24), so rendering from the network object would silently drop the host bits that SPF preserves in the mechanism's textual form and in the diagnostic. Sourcing params from the original address keeps that behavior across the switch. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace all use of the unmaintained ruby-ip gem with the standard
library's IPAddr across lib/ and the specs, and drop the gem dependency.
The prior refactors reduced the code changes to a near-mechanical
substitution:
IP.new(str) -> IPAddr.new(str)
IP === x -> IPAddr === x
IP::V4 === x -> x.ipv4?
IP::V6 === x -> x.ipv6?
#to_addr -> #to_s
#pfxlen -> #prefix
#contains?(o) -> #include?(o) (removes the IP#contains? monkey-patch)
Two spots are not 1:1, both isolated by the earlier commits:
- IPAddr masks host bits away on construction, so it cannot report
them after the fact the way ruby-ip's #offset did. SPF::Util
.ip_network_has_host_bits? now takes the original address string and
compares it against the masked network. #params already renders from
that unmasked address, so mechanism text and the InvalidMechCIDRError
diagnostic are unchanged.
- IPAddr::InvalidAddressError is an ArgumentError, so the existing
"rescue ArgumentError" fallbacks in the network parsers still apply.
The require 'ip' in eval.rb was unused and is dropped. With no code
referencing ruby-ip any more, remove it from the gemspec and regenerate
Gemfile.lock; this retires an unmaintained dependency (ruby-ip's last
release was 0.9.3) with no replacement gem added.
Full suite passes (95 examples); ip4/ip6 mechanism params and error
output verified byte-identical to the ruby-ip behavior.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
bquorning
marked this pull request as ready for review
July 14, 2026 10:08
Author
|
cc @tedaford just to get eyes on this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the third-party
ruby-ipgem with Ruby's standard libraryIPAddr, removing an external runtime dependency. The last release of ruby-ip was over 10 years ago.This PR is obviously generated with assistance from AI. Let me (the human) know if you need me to adjust some of the changes.
Changes
ruby-iptoipaddracrosslib/spf/, and drop theipdependency fromspf.gemspecandGemfile.lock.SPF::Utilhelper, sinceIPAddrdoes not expose an equivalent toIP#to_hex.IP#to_hex.ip4/ip6mechanism params from the unmasked address to preserve existing output.🤖 Generated with Claude Code