Skip to content

Commit

Permalink
Fix StringIndexOutOfBoundsException parsing host name from email
Browse files Browse the repository at this point in the history
  • Loading branch information
nullterminated committed Feb 14, 2013
1 parent ecfa4cf commit 0eec660
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ public static String hostNameForEmailString(String email) {
String hostName = StringUtils.substringAfterLast(email, "@");
// handle domain literals and quoted identifiers
hostName = StringUtils.trimToEmpty(hostName);
if(hostName.isEmpty()) { return hostName; }
int lastIndex = hostName.length() - 1;
if (hostName.lastIndexOf('>') == lastIndex) {
hostName = hostName.substring(0, lastIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ public void testHostNameForEmailString() {
Assert.assertEquals("gmail.com", ERXEmailValidator.hostNameForEmailString("[email protected]"));
Assert.assertEquals("74.125.224.182", ERXEmailValidator.hostNameForEmailString("tom@[74.125.224.182]"));
Assert.assertEquals("74.125.224.182", ERXEmailValidator.hostNameForEmailString("\"Thomas Thomson\" < tom@[ 74.125.224.182 ]>"));
Assert.assertEquals("", ERXEmailValidator.hostNameForEmailString("thomas"));
}
}

0 comments on commit 0eec660

Please sign in to comment.