Fix uncaught LEADING_HYPHEN IllegalArgumentException in host flows

This should have been getting turned into an InvalidHostNameException, but
wasn't. I've added tests for HostFlowUtils verifying the correct behavior for
this. Idn.toASCII() can throw IllegalArgumentException for some combinations
of input, including hostnames with a leading hyphen, so the call should be
inside the try block that turns IAEs into InvalidHostNameExceptions.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=139373849
This commit is contained in:
mcilwain 2016-11-16 13:48:43 -08:00 committed by Ben McIlwain
parent 438eeb5e38
commit 16c53c6996
2 changed files with 80 additions and 4 deletions

View file

@ -47,11 +47,11 @@ public class HostFlowUtils {
if (!name.equals(hostNameLowerCase)) {
throw new HostNameNotLowerCaseException(hostNameLowerCase);
}
String hostNamePunyCoded = Idn.toASCII(name);
if (!name.equals(hostNamePunyCoded)) {
throw new HostNameNotPunyCodedException(hostNamePunyCoded);
}
try {
String hostNamePunyCoded = Idn.toASCII(name);
if (!name.equals(hostNamePunyCoded)) {
throw new HostNameNotPunyCodedException(hostNamePunyCoded);
}
InternetDomainName hostName = InternetDomainName.from(name);
if (!name.equals(hostName.toString())) {
throw new HostNameNotNormalizedException(hostName.toString());