@@ -105,15 +105,13 @@ private static String innerFromUrl(@NonNull String url, @CheckForNull List<Strin
105
105
if (StringUtils .isBlank (hostName )) {
106
106
return null ;
107
107
}
108
- // let's see if we can make this more "friendly"
109
- InternetDomainName host = InternetDomainName .from (IDN .toASCII (hostName ));
110
- if (host .hasPublicSuffix ()) {
111
- String publicName = host .publicSuffix ().name ();
112
- hostName = StringUtils .removeEnd (StringUtils .removeEnd (host .name (), publicName ), "." )
113
- .toLowerCase (Locale .ENGLISH );
114
- } else {
115
- hostName = StringUtils .removeEnd (host .name (), "." ).toLowerCase (Locale .ENGLISH );
108
+
109
+ hostName = resolveInternetDomainName (hostName );
110
+ if (hostName == null ) {
111
+ return null ;
116
112
}
113
+
114
+ // let's see if we can make this more "friendly"
117
115
if (ignoredPrefixes != null ) {
118
116
for (String prefix : ignoredPrefixes ) {
119
117
if (prefix .endsWith ("." )) {
@@ -134,4 +132,20 @@ private static String innerFromUrl(@NonNull String url, @CheckForNull List<Strin
134
132
}
135
133
return hostName ;
136
134
}
135
+
136
+ private static String resolveInternetDomainName (String hostName ) {
137
+ final InternetDomainName host ;
138
+ try {
139
+ host = InternetDomainName .from (IDN .toASCII (hostName ));
140
+ } catch (IllegalArgumentException notADomainName ) {
141
+ return null ;
142
+ }
143
+
144
+ if (host .hasPublicSuffix ()) {
145
+ final String publicName = host .publicSuffix ().name ();
146
+ return StringUtils .removeEnd (StringUtils .removeEnd (host .name (), publicName ), "." ).toLowerCase (Locale .ENGLISH );
147
+ }
148
+
149
+ return StringUtils .removeEnd (host .name (), "." ).toLowerCase (Locale .ENGLISH );
150
+ }
137
151
}
0 commit comments