From f27531f5ec52420fbcebcb3fd851a80c502160fc Mon Sep 17 00:00:00 2001 From: reger Date: Sat, 19 Nov 2016 05:56:48 +0100 Subject: [PATCH] fix Domains.stripToPort, make ipv6 save --- source/net/yacy/cora/protocol/Domains.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source/net/yacy/cora/protocol/Domains.java b/source/net/yacy/cora/protocol/Domains.java index 8ed238453..f14cb1917 100644 --- a/source/net/yacy/cora/protocol/Domains.java +++ b/source/net/yacy/cora/protocol/Domains.java @@ -839,7 +839,13 @@ public class Domains { if (p > 0) target = target.substring(0, p); return target; } - + + /** + * Reads the port out of a url string (the url must start with a protocol + * like http://). If no port is given, default ports are returned + * @param target url (must start with protocol) + * @return port number + */ public static int stripToPort(String target) { int port = 80; // default port @@ -863,8 +869,11 @@ public class Domains { p = target.lastIndexOf(':'); if ( p < 0 ) return port; - // the ':' must be a port divider - port = Integer.parseInt(target.substring(p + 1)); + // the ':' must be a port divider or part of ipv6 + int pos; + if (((pos = target.lastIndexOf(']')) < 0) || (pos < p)) { + port = Integer.parseInt(target.substring(p + 1)); + } return port; }