Issue #1063 Accept empty host
This commit is contained in:
parent
f3f31d163c
commit
3dc2637d21
|
@ -0,0 +1,3 @@
|
|||
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
|
||||
#org.eclipse.jetty.LEVEL=DEBUG
|
||||
#org.eclipse.jetty.server.LEVEL=DEBUG
|
|
@ -30,11 +30,16 @@ public class HostPort
|
|||
|
||||
public HostPort(String authority) throws IllegalArgumentException
|
||||
{
|
||||
if (authority==null || authority.length()==0)
|
||||
if (authority==null)
|
||||
throw new IllegalArgumentException("No Authority");
|
||||
try
|
||||
{
|
||||
if (authority.charAt(0)=='[')
|
||||
if (authority.isEmpty())
|
||||
{
|
||||
_host=authority;
|
||||
_port=0;
|
||||
}
|
||||
else if (authority.charAt(0)=='[')
|
||||
{
|
||||
// ipv6reference
|
||||
int close=authority.lastIndexOf(']');
|
||||
|
@ -78,7 +83,7 @@ public class HostPort
|
|||
{initCause(ex);}
|
||||
};
|
||||
}
|
||||
if(_host.isEmpty())
|
||||
if(_host==null)
|
||||
throw new IllegalArgumentException("Bad host");
|
||||
if(_port<0)
|
||||
throw new IllegalArgumentException("Bad port");
|
||||
|
|
|
@ -37,6 +37,8 @@ public class HostPortTest
|
|||
public static List<String[]> testCases()
|
||||
{
|
||||
String data[][] = new String[][] {
|
||||
{"","",null},
|
||||
{":80","","80"},
|
||||
{"host","host",null},
|
||||
{"host:80","host","80"},
|
||||
{"10.10.10.1","10.10.10.1",null},
|
||||
|
@ -46,8 +48,6 @@ public class HostPortTest
|
|||
|
||||
{null,null,null},
|
||||
{"host:",null,null},
|
||||
{"",null,null},
|
||||
{":80",null,"80"},
|
||||
{"127.0.0.1:",null,null},
|
||||
{"[0::0::0::0::1]:",null,null},
|
||||
{"host:xxx",null,null},
|
||||
|
@ -76,16 +76,18 @@ public class HostPortTest
|
|||
try
|
||||
{
|
||||
HostPort hostPort = new HostPort(_authority);
|
||||
assertThat(hostPort.getHost(),is(_expectedHost));
|
||||
assertThat(_authority,hostPort.getHost(),is(_expectedHost));
|
||||
|
||||
if (_expectedPort==null)
|
||||
assertThat(hostPort.getPort(),is(0));
|
||||
assertThat(_authority,hostPort.getPort(),is(0));
|
||||
else
|
||||
assertThat(hostPort.getPort(),is(Integer.valueOf(_expectedPort)));
|
||||
assertThat(_authority,hostPort.getPort(),is(Integer.valueOf(_expectedPort)));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
assertNull(_expectedHost);
|
||||
if (_expectedHost!=null)
|
||||
e.printStackTrace();
|
||||
assertNull(_authority,_expectedHost);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue