From 55ee9279e1e92ff7707cbce06a832d0d1fd2bab2 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 6 Jun 2017 16:53:49 +0200 Subject: [PATCH] Issue #1503 Optionally strip IPv6 --- .../src/main/java/org/eclipse/jetty/util/HostPort.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/HostPort.java b/jetty-util/src/main/java/org/eclipse/jetty/util/HostPort.java index c1db3636460..5e4eba9481b 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/HostPort.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/HostPort.java @@ -22,9 +22,13 @@ package org.eclipse.jetty.util; * Parse an authority string into Host and Port *

Parse a string in the form "host:port", handling IPv4 an IPv6 hosts

* + *

The System property "org.eclipse.jetty.util.HostPort.STRIP_IPV6" can be set to a boolean + * value to control of the square brackets are stripped off IPv6 addresses.

*/ public class HostPort { + private final static boolean STRIP_IPV6 = Boolean.parseBoolean(System.getProperty("org.eclipse.jetty.util.HostPort.STRIP_IPV6","true")); + private final String _host; private final int _port; @@ -45,7 +49,7 @@ public class HostPort int close=authority.lastIndexOf(']'); if (close<0) throw new IllegalArgumentException("Bad IPv6 host"); - _host=authority.substring(0,close+1); + _host=STRIP_IPV6?authority.substring(0,close+1):authority.substring(1,close); if (authority.length()>close+1) {