Skip to content

Commit

Permalink
Issue #1063 Accept empty host
Browse files Browse the repository at this point in the history
  • Loading branch information
gregw committed Nov 3, 2016
1 parent f3f31d1 commit 3dc2637
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
3 changes: 3 additions & 0 deletions jetty-http/src/test/resources/jetty-logging.properties
@@ -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
11 changes: 8 additions & 3 deletions jetty-util/src/main/java/org/eclipse/jetty/util/HostPort.java
Expand Up @@ -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(']');
Expand Down Expand Up @@ -78,7 +83,7 @@ public HostPort(String authority) throws IllegalArgumentException
{initCause(ex);}
};
}
if(_host.isEmpty())
if(_host==null)
throw new IllegalArgumentException("Bad host");
if(_port<0)
throw new IllegalArgumentException("Bad port");
Expand Down
Expand Up @@ -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},
Expand All @@ -46,8 +48,6 @@ public static List<String[]> testCases()

{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},
Expand Down Expand Up @@ -76,16 +76,18 @@ public void test()
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);
}
}

Expand Down

0 comments on commit 3dc2637

Please sign in to comment.