Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: shorten the longest run of zeroes with :: #4

Closed
GoogleCodeExporter opened this issue Mar 14, 2015 · 7 comments
Closed

Suggestion: shorten the longest run of zeroes with :: #4

GoogleCodeExporter opened this issue Mar 14, 2015 · 7 comments

Comments

@GoogleCodeExporter
Copy link

Thanks, java-ipv6 does it's job very well! Only the compression of IPv6 is 
sometimes not perfect since it does not check for the longest run of zeroes to 
compress with :: . For instance,

com.googlecode.ipv6.IPv6Address.fromString("0:0:1::").toString()

yields ::1:0:0:0:0:0 . I checked with version 0.10.

Original issue reported on code.google.com by sto...@gmail.com on 26 Mar 2013 at 11:47

@GoogleCodeExporter
Copy link
Author

Ah indeed, good point. I'll try to find some time to look into it.

Original comment by janvanbesien@gmail.com on 26 Mar 2013 at 12:21

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

I fixed it in SVN trunk. You can create a snapshot build of that with maven to 
test it out. I'll try to create a new release later this week.

Original comment by janvanbesien@gmail.com on 26 Mar 2013 at 3:50

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Original comment by janvanbesien@gmail.com on 8 Apr 2013 at 9:26

  • Changed state: Released

@GoogleCodeExporter
Copy link
Author

Oops - it seems I shouldn't have waited for the release to test it. 8-)  
RFC5952 http://tools.ietf.org/html/rfc5952#section-4 specifies as 
recommendation for portable IPv6 addresses:

4.2.2.  Handling One 16-Bit 0 Field

   The symbol "::" MUST NOT be used to shorten just one 16-bit 0 field.
   For example, the representation 2001:db8:0:1:1:1:1:1 is correct, but
   2001:db8::1:1:1:1:1 is not correct.

Unfortunately, the implementation does now (as of 0.11) just this: return 
2001:db8::1:1:1:1:1 . This does seem to be legal according to 
http://tools.ietf.org/html/rfc4291#section-2.2 , but 
http://en.wikipedia.org/wiki/Ipv6 also recommends not doing this, though it is 
shorter.

So, it is up to you to decide whether toString() should follow the recommended 
representation according to RFC5952 or just return the shortest possible 
representation, as it does. If you want to keep the current representation I 
suggest to add something like .toPortableString() or .toRFC5952String() or 
whatever.

Here's my testcase that contains all the stuff of RFC5952 and some more random 
stuff. With v0.11 everything passes except the case mentioned above.

    private void c(String expected, String adr) {
        assertEquals(expected, IPv6Address.fromString(adr).toString());
    }

    @Test
    public void testToRFC5952String() {
        c("::", "::");
        c("1:2:3:4::", "1:2:3:4::");
        c("::1:2:3:4", "::1:2:3:4");
        c("1::2", "1::2");
        c("::2", "::2");
        c("1::", "1::");
        c("a31:200:3abc::de4", "0a31:0200:3AbC::0dE4");
        c("1::4:0:0:0", "1:0:0:0:4:0:0:0");

        c("2001:db8::1", "2001:db8::1");
        c("2001:db8::2:1", "2001:db8:0:0:0:0:2:1");
        c("2001:db8:0:1:1:1:1:1", "2001:db8:0:1:1:1:1:1");
        c("2001:db8::1:0:0:1", "2001:db8::1:0:0:1");
        c("2001:0:0:1::1", "2001:0:0:1:0:0:0:1");

        c("1:0:0:4::", "1:0:0:4::");
    }

Right now 

Original comment by sto...@gmail.com on 8 Apr 2013 at 1:44

@GoogleCodeExporter
Copy link
Author

Thanks for reporting, I didn't know. I think I'll choose to follow the 
recommendation and not to have a separate toPortableString or whatever. Will be 
for later this week.

Original comment by janvanbesien@gmail.com on 8 Apr 2013 at 2:22

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

Fixed in trunk (thanks to your useful unit test)

Original comment by janvanbesien@gmail.com on 8 Apr 2013 at 2:44

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

Original comment by janvanbesien@gmail.com on 12 Apr 2013 at 10:14

  • Changed state: Released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant