@Test public void testValidateDomainNameIsValidIdnaException() { assertFalse(validateDomainNameIsValidIdna("cnnic%.cn")); }
public static boolean validateDomainNameIsValidIdna(String domainName, boolean forSearch) { if (StringUtils.isBlank(domainName) || !domainName.contains(".")) { return false; } if (domainName.contains(BLANK_IN_DOMAIN)) { return false; } if (StringUtils.containsAny(domainName, DISALLOWED_DELIMITERS)) { return false; } if (!forSearch && !isArpaTldAndLabelIsValid(domainName)) { return false; } String punyDomainName = domainName; try { punyDomainName = geneDomainPunyName(domainName); } catch (Exception e) { LOGGER.error("generate puny name error:" + e.getMessage()); return false; } String punyWithoutLastPoint = deleteLastPoint(punyDomainName); if (!validateDomainLength(punyWithoutLastPoint)) { return false; } String domainNameWithoutLastPoint = deleteLastPoint(domainName); String[] splits = StringUtils.split(punyWithoutLastPoint, "."); if (splits.length > MAX_DOMAIN_LABEL) { return false; } if (nonReservedAsciiDomain(domainName, punyDomainName, punyWithoutLastPoint, domainNameWithoutLastPoint, forSearch)) { return isLdh(domainName); } domainName = deleteLastPoint(domainName); if (StringUtils.isBlank(domainName) || !domainName.contains(".")) { return false; } return IdnaUtil.isValidIdn(domainName); }
DomainUtil { public static boolean validateDomainNameIsValidIdna(String domainName, boolean forSearch) { if (StringUtils.isBlank(domainName) || !domainName.contains(".")) { return false; } if (domainName.contains(BLANK_IN_DOMAIN)) { return false; } if (StringUtils.containsAny(domainName, DISALLOWED_DELIMITERS)) { return false; } if (!forSearch && !isArpaTldAndLabelIsValid(domainName)) { return false; } String punyDomainName = domainName; try { punyDomainName = geneDomainPunyName(domainName); } catch (Exception e) { LOGGER.error("generate puny name error:" + e.getMessage()); return false; } String punyWithoutLastPoint = deleteLastPoint(punyDomainName); if (!validateDomainLength(punyWithoutLastPoint)) { return false; } String domainNameWithoutLastPoint = deleteLastPoint(domainName); String[] splits = StringUtils.split(punyWithoutLastPoint, "."); if (splits.length > MAX_DOMAIN_LABEL) { return false; } if (nonReservedAsciiDomain(domainName, punyDomainName, punyWithoutLastPoint, domainNameWithoutLastPoint, forSearch)) { return isLdh(domainName); } domainName = deleteLastPoint(domainName); if (StringUtils.isBlank(domainName) || !domainName.contains(".")) { return false; } return IdnaUtil.isValidIdn(domainName); } }
DomainUtil { public static boolean validateDomainNameIsValidIdna(String domainName, boolean forSearch) { if (StringUtils.isBlank(domainName) || !domainName.contains(".")) { return false; } if (domainName.contains(BLANK_IN_DOMAIN)) { return false; } if (StringUtils.containsAny(domainName, DISALLOWED_DELIMITERS)) { return false; } if (!forSearch && !isArpaTldAndLabelIsValid(domainName)) { return false; } String punyDomainName = domainName; try { punyDomainName = geneDomainPunyName(domainName); } catch (Exception e) { LOGGER.error("generate puny name error:" + e.getMessage()); return false; } String punyWithoutLastPoint = deleteLastPoint(punyDomainName); if (!validateDomainLength(punyWithoutLastPoint)) { return false; } String domainNameWithoutLastPoint = deleteLastPoint(domainName); String[] splits = StringUtils.split(punyWithoutLastPoint, "."); if (splits.length > MAX_DOMAIN_LABEL) { return false; } if (nonReservedAsciiDomain(domainName, punyDomainName, punyWithoutLastPoint, domainNameWithoutLastPoint, forSearch)) { return isLdh(domainName); } domainName = deleteLastPoint(domainName); if (StringUtils.isBlank(domainName) || !domainName.contains(".")) { return false; } return IdnaUtil.isValidIdn(domainName); } private  DomainUtil(); }
DomainUtil { public static boolean validateDomainNameIsValidIdna(String domainName, boolean forSearch) { if (StringUtils.isBlank(domainName) || !domainName.contains(".")) { return false; } if (domainName.contains(BLANK_IN_DOMAIN)) { return false; } if (StringUtils.containsAny(domainName, DISALLOWED_DELIMITERS)) { return false; } if (!forSearch && !isArpaTldAndLabelIsValid(domainName)) { return false; } String punyDomainName = domainName; try { punyDomainName = geneDomainPunyName(domainName); } catch (Exception e) { LOGGER.error("generate puny name error:" + e.getMessage()); return false; } String punyWithoutLastPoint = deleteLastPoint(punyDomainName); if (!validateDomainLength(punyWithoutLastPoint)) { return false; } String domainNameWithoutLastPoint = deleteLastPoint(domainName); String[] splits = StringUtils.split(punyWithoutLastPoint, "."); if (splits.length > MAX_DOMAIN_LABEL) { return false; } if (nonReservedAsciiDomain(domainName, punyDomainName, punyWithoutLastPoint, domainNameWithoutLastPoint, forSearch)) { return isLdh(domainName); } domainName = deleteLastPoint(domainName); if (StringUtils.isBlank(domainName) || !domainName.contains(".")) { return false; } return IdnaUtil.isValidIdn(domainName); } private  DomainUtil(); static boolean isArpaTldAndLabelIsValid(String domainName); static boolean validateDomainNameIsValidIdna(String domainName,
            boolean forSearch); static boolean validateSearchStringIsValidIdna(String searchString); static String deleteLastPoint(String paramStr); static String getLowerCaseByLabel(String str); static String safeGeneDomainPunyName(String domainName); static String geneDomainPunyName(String domainName); static String urlDecodeAndReplaceAsciiToLowercase(String str); static String replaceAsciiToLowercase(String str); static String urlDecode(String str); static String iso8859Decode(String str); static boolean isLdh(String domain); static boolean validateSearchLdnName(String searchString); }
DomainUtil { public static boolean validateDomainNameIsValidIdna(String domainName, boolean forSearch) { if (StringUtils.isBlank(domainName) || !domainName.contains(".")) { return false; } if (domainName.contains(BLANK_IN_DOMAIN)) { return false; } if (StringUtils.containsAny(domainName, DISALLOWED_DELIMITERS)) { return false; } if (!forSearch && !isArpaTldAndLabelIsValid(domainName)) { return false; } String punyDomainName = domainName; try { punyDomainName = geneDomainPunyName(domainName); } catch (Exception e) { LOGGER.error("generate puny name error:" + e.getMessage()); return false; } String punyWithoutLastPoint = deleteLastPoint(punyDomainName); if (!validateDomainLength(punyWithoutLastPoint)) { return false; } String domainNameWithoutLastPoint = deleteLastPoint(domainName); String[] splits = StringUtils.split(punyWithoutLastPoint, "."); if (splits.length > MAX_DOMAIN_LABEL) { return false; } if (nonReservedAsciiDomain(domainName, punyDomainName, punyWithoutLastPoint, domainNameWithoutLastPoint, forSearch)) { return isLdh(domainName); } domainName = deleteLastPoint(domainName); if (StringUtils.isBlank(domainName) || !domainName.contains(".")) { return false; } return IdnaUtil.isValidIdn(domainName); } private  DomainUtil(); static boolean isArpaTldAndLabelIsValid(String domainName); static boolean validateDomainNameIsValidIdna(String domainName,
            boolean forSearch); static boolean validateSearchStringIsValidIdna(String searchString); static String deleteLastPoint(String paramStr); static String getLowerCaseByLabel(String str); static String safeGeneDomainPunyName(String domainName); static String geneDomainPunyName(String domainName); static String urlDecodeAndReplaceAsciiToLowercase(String str); static String replaceAsciiToLowercase(String str); static String urlDecode(String str); static String iso8859Decode(String str); static boolean isLdh(String domain); static boolean validateSearchLdnName(String searchString); static final String XN_PREFIX; static final String ACE_PREFIX; static final int MAX_DOMAIN_LENGTH_WITHOUT_LAST_DOT; static final int MIN_DOMAIN_LENGTH_WITHOUT_LAST_DOT; static final String ARPA_SUFFIX; static final String IPV4_ARPA_SUFFIX; static final String IPV6_ARPA_SUFFIX; static final int MAX_ASCII_CODE; static final String BLANK_IN_DOMAIN; static final java.lang.String DISALLOWED_DELIMITERS; }