Skip to content
This repository was archived by the owner on Apr 5, 2022. It is now read-only.

IPv6-Addresses in URLs #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.0.1.BUILD-SNAPSHOT
version=1.0.1.BUILD-KOA
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably needs to be removed from the PR.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));

}

Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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*)";

Expand Down