Repository navigation
Drop the zone ID when IPAddr#native returns an IPv4 address - #142
Merged
Merged
Conversation
IPAddr.new("::ffff:192.168.1.2%eth0").native kept the IPv6 zone ID.
The result is IPv4, so the zone is not shown by #to_s and #zone_id
raises, but it is still part of #hash. So the address was == to
IPAddr.new("192.168.1.2") but not #eql?, and Hash, Set and #uniq
treated them as different addresses.
Collaborator
|
@bardrop Nice catch! Thank you for the fix. |
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.
IPAddr#nativekeeps the IPv6 zone ID when it turns an IPv4-mapped (or IPv4-compatible) address into IPv4:The zone can't be seen or read on the IPv4 result, but
#hashstill includes@zone_id, so the two addresses are==but noteql?. Hash keys,Setand#uniqthen treat them as different addresses. Python'sipaddressalso drops the zone here (IPv6Address("::ffff:192.168.1.2%eth0").ipv4_mappedisIPv4Address('192.168.1.2')).The fix clears
@zone_idin#setwhen the family becomesAF_INET, which is where#nativealready narrows the mask to 32 bits.#nativeon an address that is not mapped or compatible still returnsself, so plain IPv6 addresses keep their zone.Tests: new
test_native_drops_zone_id(mapped and compatible forms). It fails before the change and passes after;bundle exec rake testpasses (43 tests, 635 assertions).