diff --git a/testsuite/unit-tests/src/test/java/org/jboss/resteasy/test/util/UriBuilderTest.java b/testsuite/unit-tests/src/test/java/org/jboss/resteasy/test/util/UriBuilderTest.java index 9c5cef1a3e5..5773655ca66 100755 --- a/testsuite/unit-tests/src/test/java/org/jboss/resteasy/test/util/UriBuilderTest.java +++ b/testsuite/unit-tests/src/test/java/org/jboss/resteasy/test/util/UriBuilderTest.java @@ -1049,6 +1049,51 @@ public void uriBuilderTest() throws Exception { } + @Test + public void additionalCheckForIPv6() throws Exception { + + Assert.assertEquals("http://0:0:0:0:0:0:0:1", UriBuilder.fromUri("http://0:0:0:0:0:0:0:1").build().toString()); + Assert.assertEquals("http://::1", UriBuilder.fromUri("http://::1").build().toString()); + Assert.assertEquals("http://0:0:0:0:0:0:0:1", UriBuilder.fromUri("http://{host}").build("0:0:0:0:0:0:0:1").toString()); + //Assert.assertEquals("http://[0:0:0:0:0:0:0:1]:8080", UriBuilder.fromUri("http://{host}:8080").build("[0:0:0:0:0:0:0:1]").toString()); + + // inspiration from https://stackoverflow.com/a/17871737 + + Assert.assertEquals("http://1:2:3:4:5:6:7:8", UriBuilder.fromUri("http://1:2:3:4:5:6:7:8").build().toString()); + Assert.assertEquals("http://1::", UriBuilder.fromUri("http://1::").build().toString()); + Assert.assertEquals("http://1:2:3:4:5:6:7::", UriBuilder.fromUri("http://1:2:3:4:5:6:7::").build().toString()); + Assert.assertEquals("http://1::8", UriBuilder.fromUri("http://1::8").build().toString()); + Assert.assertEquals("http://1:2:3:4:5:6::8", UriBuilder.fromUri("http://1:2:3:4:5:6::8").build().toString()); + Assert.assertEquals("http://1::7:8", UriBuilder.fromUri("http://1::7:8").build().toString()); + Assert.assertEquals("http://1:2:3:4:5::7:8", UriBuilder.fromUri("http://1:2:3:4:5::7:8").build().toString()); + Assert.assertEquals("http://1:2:3:4:5::8", UriBuilder.fromUri("http://1:2:3:4:5::8").build().toString()); + Assert.assertEquals("http://1::6:7:8", UriBuilder.fromUri("http://1::6:7:8").build().toString()); + Assert.assertEquals("http://1:2:3:4::6:7:8", UriBuilder.fromUri("http://1:2:3:4::6:7:8").build().toString()); + Assert.assertEquals("http://1:2:3:4::8", UriBuilder.fromUri("http://1:2:3:4::8").build().toString()); + Assert.assertEquals("http://1::5:6:7:8", UriBuilder.fromUri("http://1::5:6:7:8").build().toString()); + Assert.assertEquals("http://1:2:3::5:6:7:8", UriBuilder.fromUri("http://1:2:3::5:6:7:8").build().toString()); + Assert.assertEquals("http://1:2:3::8", UriBuilder.fromUri("http://1:2:3::8").build().toString()); + Assert.assertEquals("http://1::4:5:6:7:8", UriBuilder.fromUri("http://1::4:5:6:7:8").build().toString()); + Assert.assertEquals("http://1:2::4:5:6:7:8", UriBuilder.fromUri("http://1:2::4:5:6:7:8").build().toString()); + Assert.assertEquals("http://1:2::8", UriBuilder.fromUri("http://1:2::8").build().toString()); + Assert.assertEquals("http://1::3:4:5:6:7:8", UriBuilder.fromUri("http://1::3:4:5:6:7:8").build().toString()); + Assert.assertEquals("http://1::8", UriBuilder.fromUri("http://1::8").build().toString()); + Assert.assertEquals("http://::2:3:4:5:6:7:8", UriBuilder.fromUri("http://::2:3:4:5:6:7:8").build().toString()); + Assert.assertEquals("http://::3:4:5:6:7:8", UriBuilder.fromUri("http://::3:4:5:6:7:8").build().toString()); + Assert.assertEquals("http://::8", UriBuilder.fromUri("http://::8").build().toString()); + Assert.assertEquals("http://::", UriBuilder.fromUri("http://::").build().toString()); + + //Assert.assertEquals("http://fe80::7:8%eth0", UriBuilder.fromUri("http://fe80::7:8%eth0").build().toString()); + //Assert.assertEquals("http://fe80::7:8%1", UriBuilder.fromUri("http://fe80::7:8%1").build().toString()); + + Assert.assertEquals("http://::255.255.255.255", UriBuilder.fromUri("http://::255.255.255.255").build().toString()); + Assert.assertEquals("http://::ffff:255.255.255.255", UriBuilder.fromUri("http://::ffff:255.255.255.255").build().toString()); + Assert.assertEquals("http://::ffff:0:255.255.255.255", UriBuilder.fromUri("http://::ffff:0:255.255.255.255").build().toString()); + + Assert.assertEquals("http://2001:db8:3:4::192.0.2.33", UriBuilder.fromUri("http://2001:db8:3:4::192.0.2.33").build().toString()); + Assert.assertEquals("http://64:ff9b::192.0.2.33", UriBuilder.fromUri("http://64:ff9b::192.0.2.33").build().toString()); + } + public void printParse(String uri) { logger.info("--- " + uri); Matcher match = uriPattern.matcher(uri);