@Test public void testValidateSearchStringIsValidIdna() { assertTrue(validateSearchStringIsValidIdna("cn*")); assertTrue(validateSearchStringIsValidIdna("中国*")); assertTrue(validateSearchStringIsValidIdna("cn.中国*")); assertTrue(validateSearchStringIsValidIdna("cn中国*")); assertTrue(validateSearchStringIsValidIdna("*.cn")); assertTrue(validateSearchStringIsValidIdna("*cn")); assertTrue(validateSearchStringIsValidIdna("*")); assertFalse(validateSearchStringIsValidIdna("σειράτάξησυπουργείωνΣύνθεσηυπουργικούσυμβουλίουουουο*.bnnhg")); assertFalse(validateSearchStringIsValidIdna("%CF*.bnnhg")); assertFalse(validateSearchStringIsValidIdna("1**.bnnhg")); assertFalse(validateSearchStringIsValidIdna("-*.bnnhg")); assertFalse(validateSearchStringIsValidIdna("%CF*.bnnhg")); assertFalse(validateSearchStringIsValidIdna("Σ*.bnnhg")); assertFalse(validateSearchStringIsValidIdna("ύύ--*.bnnhg")); assertTrue(validateSearchStringIsValidIdna("xn--123*.bnnhg")); assertTrue(validateSearchStringIsValidIdna("xn--*.bnnhg")); assertTrue(validateSearchStringIsValidIdna("xn--*")); assertTrue(validateSearchStringIsValidIdna("%CF%83*.bnnhg")); assertTrue(validateSearchStringIsValidIdna("cn--*.bnnhg")); assertTrue(validateSearchStringIsValidIdna("ύ*.bnnhg")); assertTrue(validateSearchStringIsValidIdna("cnnic*.cn")); assertTrue(validateSearchStringIsValidIdna("xn--fiqa61au8b7zsevnm8ak20mc4a87e*.cn")); assertTrue(validateSearchStringIsValidIdna("xn--elaaaa*.com")); assertTrue(validateSearchStringIsValidIdna("xn--123123*.cn")); assertTrue(validateSearchStringIsValidIdna("中国互联*.cn")); assertTrue(validateSearchStringIsValidIdna("\u0205*.cn")); assertTrue(validateSearchStringIsValidIdna("mamalookhahababalookhehewhowholookhouhoumamalookaiaibabalookouo*.cn")); assertTrue(validateSearchStringIsValidIdna("xn--hxaajaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa*.bnnhg")); assertTrue(validateSearchStringIsValidIdna("mamalookhahababalookhehewhowholookhouhoumamalookaiaibabalookouo*.mamalookhahababalookhehewhowholookhouhoumamalookaiaibabalookouo.mamalookhahababalookhehewhowholookhouhoumamalookaiaibabalookouo.mamalookhahababalookhehewhowholookhouhoumamalookaiaibabal1.cn")); assertTrue(validateSearchStringIsValidIdna("mamalookhahababalookhehewhowholookhouhoumamalookaiaibabalookouo*.mamalookhahababalookhehewhowholookhouhoumamalookaiaibabalookouo.mamalookhahababalookhehewhowholookhouhoumamalookaiaibabalookouo.mamalookhahababalookhehewhowholookhouhoumamalookaiaibabal1.cn.")); assertTrue(validateSearchStringIsValidIdna("xn--hxaajaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa*.xn--hxaajaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa.xn--hxaajaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa.jaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa.bnnhg")); assertTrue(validateSearchStringIsValidIdna("xn--hxaajaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa*.xn--hxaajaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa.xn--hxaajaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa.jaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa.bnnhg.")); assertTrue(validateSearchStringIsValidIdna("1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.com*")); assertTrue(validateSearchStringIsValidIdna("1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.com*.")); assertTrue(validateSearchStringIsValidIdna("cnnic*.cn")); assertTrue(validateSearchStringIsValidIdna("xn--fiqa61au8b7zsevnm8ak20mc4a87e.cn*.")); assertTrue(validateSearchStringIsValidIdna("xn--elaaaa.com.*")); assertTrue(validateSearchStringIsValidIdna("xn--ELAAAA.COM*.")); assertTrue(validateSearchStringIsValidIdna("%C8%85%C8%85%C8%85%C8%85*.com")); assertTrue(validateSearchStringIsValidIdna("%E4%B8%AD%E5%9B%BD%E4%BA%92%E8%81%94%E7%BD%91%E7%BB%9C%E4%BF%A1%E6%81%AF%E4%B8%AD%E5%BF%83.cn*")); assertTrue(validateSearchStringIsValidIdna("256.in-addr.arpa*")); assertTrue(validateSearchStringIsValidIdna("1.2.3.4.5.in-addr.arpa*.")); assertFalse(validateSearchStringIsValidIdna(".1.in-addr.arpa*")); assertFalse(validateSearchStringIsValidIdna("1..5.in-addr.arpa*")); assertTrue(validateSearchStringIsValidIdna("1.2-5.in-addr.arpa*")); assertFalse(validateSearchStringIsValidIdna("1.-25.in-addr.arpa*")); assertFalse(validateSearchStringIsValidIdna("1.-25.in-addr.arpa*..")); assertFalse(validateSearchStringIsValidIdna("1.-25-.in-addr.arpa*")); assertFalse(validateSearchStringIsValidIdna("abcd123456789012345678901234567890123456789012345678901234567890.cn*")); assertFalse(validateSearchStringIsValidIdna("xn--hxaajaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa1.bnnhg*")); assertFalse(validateSearchStringIsValidIdna("1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.n.*")); assertFalse(validateSearchStringIsValidIdna("1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.1.2.3.4.5.6.7.8.9.0.a.b.c.d.e.f.g.h.i.j.k.n*")); assertFalse(validateSearchStringIsValidIdna("xn--hxaajaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa.xn--hxaajaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa.xn--hxaajaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa.jaoebldbselhkqsqmapxidccaaahjrgk3chhdip9bclcgddbb4ooioa1.bnnhg*")); assertFalse(validateSearchStringIsValidIdna("mamalookhahababalookhehewhowholookhouhoumamalookaiaibabalookouoo.mamalookhahababalookhehewhowholookhouhoumamalookaiaibabalookouo.mamalookhahababalookhehewhowholookhouhoumamalookaiaibabalookouo.mamalookhahababalookhehewhowholookhouhoumamalookaiaibabal1.cn")); assertFalse(validateSearchStringIsValidIdna("cnnic。cn*")); assertFalse(validateSearchStringIsValidIdna(".cnnic.cn*")); assertFalse(validateSearchStringIsValidIdna("ww..he.cn*")); assertFalse(validateSearchStringIsValidIdna("-cnnic-.cn*")); assertFalse(validateSearchStringIsValidIdna("cnnic-.cn*")); assertFalse(validateSearchStringIsValidIdna("ab.-.cn*")); assertFalse(validateSearchStringIsValidIdna("cnnic_cn*")); assertFalse(validateSearchStringIsValidIdna("cnnic%2C.cn*")); assertFalse(validateSearchStringIsValidIdna("cnnic%25.cn*")); assertFalse(validateSearchStringIsValidIdna("cnnic*.cn*")); assertFalse(validateSearchStringIsValidIdna("cnni+c.cn*")); assertFalse(validateSearchStringIsValidIdna("cn<n>ic.cn*")); assertFalse(validateSearchStringIsValidIdna("cnnic. .cn*")); assertFalse(validateSearchStringIsValidIdna("^cnnic.cn*")); assertFalse(validateSearchStringIsValidIdna("cnnic,.cn*")); assertFalse(validateSearchStringIsValidIdna("cnnic:cn*")); assertTrue(validateSearchStringIsValidIdna("cnnic*.cn")); assertFalse(validateSearchStringIsValidIdna("cnni+c.cn*")); assertFalse(validateSearchStringIsValidIdna("cn<n>ic.cn*")); assertFalse(validateSearchStringIsValidIdna("xn--6iq8zxlq4ga518lea949ds8ax1at67b8mc412a4uaaa4423b5n2b2s5b340b*.cn")); assertFalse(validateSearchStringIsValidIdna("xn--6iq8zxlq4ga518lea949ds8ax1at67b8mc412a4uaw57iy98ao71bi59a.xn--6iq8zxlq4ga518lea949ds8ax1at67b8mc412a4uaw57iy98ao71bi59a.xn--6iq8zxlq4ga518lea949ds8ax1at67b8mc412a4uaw57iy98ao71bi59a.xn--6iq8zxlq4ga518lea949ds8ax1at67b8mc412a4uaw57iy98ao71bi59a.edu.cn*")); assertFalse(validateSearchStringIsValidIdna("xn--6iq8zxlq4ga518lea949ds8ax1at67b8mc412a4uaw57iy98ao71bi59a.xn--6iq8zxlq4ga518lea949ds8ax1at67b8mc412a4uaw57iy98ao71bi59a.xn--6iq8zxlq4ga518lea949ds8ax1at67b8mc412a4uaw57iy98ao71bi59a.xn--6iq8zxlq4ga518lea949ds8ax1at67b8mc412a4uaw57iy98ao71bi59a.xn--6iq8zxlq4ga518lea949ds8ax1at67b8mc412a4uaw57iy98ao71bi59a.cn*")); assertFalse(validateSearchStringIsValidIdna("12--11中国*.中国")); assertFalse(validateSearchStringIsValidIdna("xn--5us中国*.中国")); assertFalse(validateSearchStringIsValidIdna("xn--5us.%E4%B8%AD%E5%9B%BD*")); assertFalse(validateSearchStringIsValidIdna("xn--5us.%E4%B8%AD%E5%9B%BD*")); assertFalse(validateSearchStringIsValidIdna("xn--5us.中国*")); assertFalse(validateSearchStringIsValidIdna("xn--5us*.qqéa.cn")); assertTrue(validateSearchStringIsValidIdna("55--*123.xn--fiqs8s")); assertTrue(validateSearchStringIsValidIdna("5*--123.xn--fiqs8s")); assertFalse(validateSearchStringIsValidIdna(".好.中国*")); assertFalse(validateSearchStringIsValidIdna("12..好.中国*")); assertFalse(validateSearchStringIsValidIdna("-好.中国*")); assertFalse(validateSearchStringIsValidIdna("好-.中国*")); assertFalse(validateSearchStringIsValidIdna("好-.中国*")); assertFalse(validateSearchStringIsValidIdna("-好-.中国*")); assertFalse(validateSearchStringIsValidIdna("好.-.中国*")); assertFalse(validateSearchStringIsValidIdna("123〳*.中国")); assertFalse(validateSearchStringIsValidIdna("123Ā*.中国")); assertFalse(validateSearchStringIsValidIdna("123Ƽ*.中国")); assertFalse(validateSearchStringIsValidIdna("123஝஝஝஝*.中国")); assertFalse(validateSearchStringIsValidIdna("123઱஝஝*.中国")); assertFalse(validateSearchStringIsValidIdna("123�஝஝*.中国")); assertFalse(validateSearchStringIsValidIdna("%C81%851%C81%815%C81%851%C81%851.com*")); assertFalse(validateSearchStringIsValidIdna("好.-.中国*")); assertFalse(validateSearchStringIsValidIdna("好.-.中国*")); assertFalse(validateSearchStringIsValidIdna("好.-.中国*")); assertFalse(validateSearchStringIsValidIdna("好.-.中国*")); }
public static boolean validateSearchStringIsValidIdna(String searchString) { if (StringUtils.isBlank(searchString)) { return false; } if (searchString.contains(BLANK_IN_DOMAIN)) { return false; } if (1 < StringUtils.countMatches(searchString, StringUtil.ASTERISK)) { return false; } String domainName = searchString.replace(StringUtil.ASTERISK, ""); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace(StringUtil.ASTERISK, StringUtil.TLD_SPLITOR); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace(StringUtil.ASTERISK, "1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace("*", ".1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace("*", "1.1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } return false; }
DomainUtil { public static boolean validateSearchStringIsValidIdna(String searchString) { if (StringUtils.isBlank(searchString)) { return false; } if (searchString.contains(BLANK_IN_DOMAIN)) { return false; } if (1 < StringUtils.countMatches(searchString, StringUtil.ASTERISK)) { return false; } String domainName = searchString.replace(StringUtil.ASTERISK, ""); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace(StringUtil.ASTERISK, StringUtil.TLD_SPLITOR); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace(StringUtil.ASTERISK, "1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace("*", ".1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace("*", "1.1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } return false; } }
DomainUtil { public static boolean validateSearchStringIsValidIdna(String searchString) { if (StringUtils.isBlank(searchString)) { return false; } if (searchString.contains(BLANK_IN_DOMAIN)) { return false; } if (1 < StringUtils.countMatches(searchString, StringUtil.ASTERISK)) { return false; } String domainName = searchString.replace(StringUtil.ASTERISK, ""); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace(StringUtil.ASTERISK, StringUtil.TLD_SPLITOR); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace(StringUtil.ASTERISK, "1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace("*", ".1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace("*", "1.1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } return false; } private  DomainUtil(); }
DomainUtil { public static boolean validateSearchStringIsValidIdna(String searchString) { if (StringUtils.isBlank(searchString)) { return false; } if (searchString.contains(BLANK_IN_DOMAIN)) { return false; } if (1 < StringUtils.countMatches(searchString, StringUtil.ASTERISK)) { return false; } String domainName = searchString.replace(StringUtil.ASTERISK, ""); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace(StringUtil.ASTERISK, StringUtil.TLD_SPLITOR); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace(StringUtil.ASTERISK, "1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace("*", ".1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace("*", "1.1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } return false; } 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 validateSearchStringIsValidIdna(String searchString) { if (StringUtils.isBlank(searchString)) { return false; } if (searchString.contains(BLANK_IN_DOMAIN)) { return false; } if (1 < StringUtils.countMatches(searchString, StringUtil.ASTERISK)) { return false; } String domainName = searchString.replace(StringUtil.ASTERISK, ""); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace(StringUtil.ASTERISK, StringUtil.TLD_SPLITOR); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace(StringUtil.ASTERISK, "1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace("*", ".1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } domainName = searchString.replace("*", "1.1"); if (validateDomainNameIsValidIdna(domainName, true)) { return true; } return false; } 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; }