carterkozak commented on a change in pull request #279:
URL:
https://github.com/apache/httpcomponents-core/pull/279#discussion_r615423121
##########
File path: httpcore5/src/main/java/org/apache/hc/core5/net/Host.java
##########
@@ -60,14 +60,31 @@ public Host(final String name, final int port) {
static Host parse(final CharSequence s, final Tokenizer.Cursor cursor)
throws URISyntaxException {
final Tokenizer tokenizer = Tokenizer.INSTANCE;
- final String hostName = tokenizer.parseContent(s, cursor,
URISupport.PORT_SEPARATORS);
+ final String hostName;
+ final boolean ipv6Brackets = !cursor.atEnd() &&
s.charAt(cursor.getPos()) == '[';
+ if (ipv6Brackets) {
+ cursor.updatePos(cursor.getPos() + 1);
+ hostName = tokenizer.parseContent(s, cursor,
URISupport.IPV6_HOST_TERMINATORS);
+ if (cursor.atEnd() || !(s.charAt(cursor.getPos()) == ']')) {
+ throw URISupport.createException(s, cursor, "Expected an IPv6
closing bracket ']'");
+ }
+ cursor.updatePos(cursor.getPos() + 1);
+ if (!InetAddressUtils.isIPv6Address(hostName)) {
+ throw URISupport.createException(s, cursor, "Expected an IPv6
address");
+ }
+ } else {
+ hostName = tokenizer.parseContent(s, cursor,
URISupport.PORT_SEPARATORS);
+ }
String portText = null;
if (!cursor.atEnd() && s.charAt(cursor.getPos()) == ':') {
cursor.updatePos(cursor.getPos() + 1);
portText = tokenizer.parseContent(s, cursor,
URISupport.TERMINATORS);
}
final int port;
if (!TextUtils.isBlank(portText)) {
+ if (!ipv6Brackets && portText.contains(":")) {
+ throw URISupport.createException(s, cursor, "Expected IPv6
addresses to be enclosed in braces");
Review comment:
Good catch, I've updated to "brackets" to match the RFC wording.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]