@Test public void allowTrailingDot() { assertEquals(Hosts.parse("example.com"), Hosts.parse("example.com.")); assertEquals(Hosts.parse("example"), Hosts.parse("example.")); assertEquals(Hosts.parse("1.1.1.1"), Hosts.parse("1.1.1.1.")); }
@Nonnull static Host parse(String hostname) { String ascii = validateAndConvertToAscii(hostname); Host host; if (Ip6.isIpv6(ascii)) { host = Ip6.parse(ascii); } else { if (ascii.endsWith(".")) { ascii = ascii.substring(0, ascii.length() - 1); } if (Ip4.isIpv4(ascii)) { host = Ip4.parse(ascii); } else { host = Dns.parse(ascii); } } if (host == null) { throw new IllegalArgumentException("Invalid hostname: " + hostname); } return host; }
Hosts { @Nonnull static Host parse(String hostname) { String ascii = validateAndConvertToAscii(hostname); Host host; if (Ip6.isIpv6(ascii)) { host = Ip6.parse(ascii); } else { if (ascii.endsWith(".")) { ascii = ascii.substring(0, ascii.length() - 1); } if (Ip4.isIpv4(ascii)) { host = Ip4.parse(ascii); } else { host = Dns.parse(ascii); } } if (host == null) { throw new IllegalArgumentException("Invalid hostname: " + hostname); } return host; } }
Hosts { @Nonnull static Host parse(String hostname) { String ascii = validateAndConvertToAscii(hostname); Host host; if (Ip6.isIpv6(ascii)) { host = Ip6.parse(ascii); } else { if (ascii.endsWith(".")) { ascii = ascii.substring(0, ascii.length() - 1); } if (Ip4.isIpv4(ascii)) { host = Ip4.parse(ascii); } else { host = Dns.parse(ascii); } } if (host == null) { throw new IllegalArgumentException("Invalid hostname: " + hostname); } return host; }  }
Hosts { @Nonnull static Host parse(String hostname) { String ascii = validateAndConvertToAscii(hostname); Host host; if (Ip6.isIpv6(ascii)) { host = Ip6.parse(ascii); } else { if (ascii.endsWith(".")) { ascii = ascii.substring(0, ascii.length() - 1); } if (Ip4.isIpv4(ascii)) { host = Ip4.parse(ascii); } else { host = Dns.parse(ascii); } } if (host == null) { throw new IllegalArgumentException("Invalid hostname: " + hostname); } return host; }   }
Hosts { @Nonnull static Host parse(String hostname) { String ascii = validateAndConvertToAscii(hostname); Host host; if (Ip6.isIpv6(ascii)) { host = Ip6.parse(ascii); } else { if (ascii.endsWith(".")) { ascii = ascii.substring(0, ascii.length() - 1); } if (Ip4.isIpv4(ascii)) { host = Ip4.parse(ascii); } else { host = Dns.parse(ascii); } } if (host == null) { throw new IllegalArgumentException("Invalid hostname: " + hostname); } return host; }    }