diff --git a/gradle.properties b/gradle.properties index 1c7ff0f6..ade263a5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=1.0.1.BUILD-SNAPSHOT +version=1.0.1.BUILD-KOA diff --git a/spring-android-rest-template-test/src/main/java/org/springframework/web/util/UriUtilsTests.java b/spring-android-rest-template-test/src/main/java/org/springframework/web/util/UriUtilsTests.java index 1fe2ebb6..0768b8d0 100644 --- a/spring-android-rest-template-test/src/main/java/org/springframework/web/util/UriUtilsTests.java +++ b/spring-android-rest-template-test/src/main/java/org/springframework/web/util/UriUtilsTests.java @@ -45,6 +45,8 @@ public void testEncodeUserInfo() throws UnsupportedEncodingException { public void testEncodeHost() throws UnsupportedEncodingException { assertEquals("Invalid encoded result", "foobar", UriUtils.encodeHost("foobar", ENC)); assertEquals("Invalid encoded result", "foo%20bar", UriUtils.encodeHost("foo bar", ENC)); + assertEquals("Invalid encoded result", "[::1]", UriUtils.encodeHost("[::1]", ENC)); + assertEquals("Invalid encoded result", "[fe80::a2cf:33ff:fee2:124f]", UriUtils.encodeHost("[fe80::a2cf:33ff:fee2:124f]", ENC)); } @SmallTest @@ -132,6 +134,12 @@ public void testEncodeUri() throws UnsupportedEncodingException { assertEquals("Invalid encoded URI", "file:///~/calendar", UriUtils.encodeUri("file:///~/calendar", ENC)); assertEquals("Invalid encoded URI", "http://example.com/query=foo@bar", UriUtils.encodeUri("http://example.com/query=foo@bar", ENC)); + assertEquals("Invalid encoded URI", "http://[::1]/rest.xml", + UriUtils.encodeUri("http://[::1]/rest.xml", ENC)); + assertEquals("Invalid encoded URI", "http://[::1]:8080/rest.xml", + UriUtils.encodeUri("http://[::1]:8080/rest.xml", ENC)); + assertEquals("Invalid encoded URI", "http://[fe80::a2cf:33ff:fee2:124f]:8080/rest.xml", + UriUtils.encodeUri("http://[fe80::a2cf:33ff:fee2:124f]:8080/rest.xml", ENC)); } @@ -156,6 +164,12 @@ public void testEncodeHttpUrl() throws UnsupportedEncodingException { UriUtils.encodeHttpUrl("http://java.sun.com/j2se/1.3/", ENC)); assertEquals("Invalid encoded HTTP URL", "http://example.com/query=foo@bar", UriUtils.encodeHttpUrl("http://example.com/query=foo@bar", ENC)); + assertEquals("Invalid encoded HTTP URL", "http://[::1]/rest.xml", + UriUtils.encodeHttpUrl("http://[::1]/rest.xml", ENC)); + assertEquals("Invalid encoded HTTP URL", "http://[::1]:8080/rest.xml", + UriUtils.encodeHttpUrl("http://[::1]:8080/rest.xml", ENC)); + assertEquals("Invalid encoded HTTP URL", "http://[fe80::a2cf:33ff:fee2:124f]:8080/rest.xml", + UriUtils.encodeHttpUrl("http://[fe80::a2cf:33ff:fee2:124f]:8080/rest.xml", ENC)); // SPR-8974 assertEquals("http://example.org?format=json&url=http://another.com?foo=bar", diff --git a/spring-android-rest-template/src/main/java/org/springframework/web/util/UriComponents.java b/spring-android-rest-template/src/main/java/org/springframework/web/util/UriComponents.java index 224f8ab7..df05e750 100644 --- a/spring-android-rest-template/src/main/java/org/springframework/web/util/UriComponents.java +++ b/spring-android-rest-template/src/main/java/org/springframework/web/util/UriComponents.java @@ -288,6 +288,10 @@ static String encodeUriComponent(String source, String encoding, Type type) } Assert.hasLength(encoding, "'encoding' must not be empty"); + + // do not encode ipv6-hostnames like [::1] + if(type==Type.HOST && source.startsWith("[") && source.endsWith("]")) + return source; byte[] bytes = encodeBytes(source.getBytes(encoding), type); return new String(bytes, "US-ASCII"); diff --git a/spring-android-rest-template/src/main/java/org/springframework/web/util/UriComponentsBuilder.java b/spring-android-rest-template/src/main/java/org/springframework/web/util/UriComponentsBuilder.java index d6712aa1..36caefd1 100644 --- a/spring-android-rest-template/src/main/java/org/springframework/web/util/UriComponentsBuilder.java +++ b/spring-android-rest-template/src/main/java/org/springframework/web/util/UriComponentsBuilder.java @@ -61,7 +61,7 @@ public class UriComponentsBuilder { private static final String USERINFO_PATTERN = "([^@/]*)"; - private static final String HOST_PATTERN = "([^/?#:]*)"; + private static final String HOST_PATTERN = "(\\[[:0-9a-f]*\\]|[^/?#:\\[\\]]*)"; private static final String PORT_PATTERN = "(\\d*)";