@@ -218,6 +218,42 @@ public void testToAddrStringIPv6WithZoneId(){
218218 InetAddresses .forString ("::1.2.3.4%0" )));
219219 }
220220
221+ public void testToAddrStringIPv6WithInvalidZoneId (){
222+ IllegalArgumentException e = null ;
223+
224+ e = expectThrows (IllegalArgumentException .class , () -> InetAddresses .forString ("::1%fred" ));
225+ assertThat (e .getMessage (), Matchers .containsString ("is not an IP string literal" ));
226+
227+ e = expectThrows (IllegalArgumentException .class , () -> InetAddresses .forString ("::1%%" ));
228+ assertThat (e .getMessage (), Matchers .containsString ("is not an IP string literal" ));
229+
230+ e = expectThrows (IllegalArgumentException .class , () -> InetAddresses .forString ("%::1" ));
231+ assertThat (e .getMessage (), Matchers .containsString ("is not an IP string literal" ));
232+
233+ e = expectThrows (IllegalArgumentException .class , () -> InetAddresses .forString ("0::0:0:0:0:0:0%:1" ));
234+ assertThat (e .getMessage (), Matchers .containsString ("is not an IP string literal" ));
235+
236+ e = expectThrows (IllegalArgumentException .class , () -> InetAddresses .forString ("::1%1.2.3.4" ));
237+ assertThat (e .getMessage (), Matchers .containsString ("is not an IP string literal" ));
238+ }
239+
240+ public void testToAddrStringZoneIdDelimiterCannotAppearRightAfterOtherDelimiters (){
241+ IllegalArgumentException e = null ;
242+
243+ e = expectThrows (IllegalArgumentException .class , () -> InetAddresses .forString ("::1:%0" ));
244+ assertThat (e .getMessage (), Matchers .containsString ("is not an IP string literal" ));
245+
246+ e = expectThrows (IllegalArgumentException .class , () -> InetAddresses .forString ("::1:1.2.3.%0" ));
247+ assertThat (e .getMessage (), Matchers .containsString ("is not an IP string literal" ));
248+ }
249+
250+ public void testToAddrStringIPv4DoesNotAllowZoneId (){
251+ IllegalArgumentException e = null ;
252+
253+ e = expectThrows (IllegalArgumentException .class , () -> InetAddresses .forString ("1.2.3.4%0" ));
254+ assertThat (e .getMessage (), Matchers .containsString ("is not an IP string literal" ));
255+ }
256+
221257 public void testToUriStringIPv4 () {
222258 String ipStr = "1.2.3.4" ;
223259 InetAddress ip = InetAddresses .forString (ipStr );
0 commit comments