@@ -50,6 +50,20 @@ private record FormatCheck(Predicate<String> isValid, String message) {}
5050 private static final Pattern IPV4 =
5151 Pattern .compile ("^((25[0-5]|2[0-4]\\ d|1?\\ d?\\ d)\\ .){3}(25[0-5]|2[0-4]\\ d|1?\\ d?\\ d)$" );
5252
53+ private static final Pattern IPV6 =
54+ Pattern .compile (
55+ "^("
56+ + "([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}"
57+ + "|([0-9a-fA-F]{1,4}:){1,7}:"
58+ + "|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}"
59+ + "|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}"
60+ + "|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}"
61+ + "|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}"
62+ + "|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}"
63+ + "|[0-9a-fA-F]{1,4}:(:[0-9a-fA-F]{1,4}){1,6}"
64+ + "|:((:[0-9a-fA-F]{1,4}){1,7}|:)"
65+ + ")$" );
66+
5367 private static final Pattern HOSTNAME =
5468 Pattern .compile (
5569 "^(?=.{1,253}$)([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)"
@@ -69,7 +83,8 @@ private record FormatCheck(Predicate<String> isValid, String message) {}
6983 Map .entry (
7084 "hostname" ,
7185 new FormatCheck (s -> HOSTNAME .matcher (s ).matches (), "not a valid hostname" )),
72- Map .entry ("ipv4" , new FormatCheck (s -> IPV4 .matcher (s ).matches (), "not a valid ipv4" )));
86+ Map .entry ("ipv4" , new FormatCheck (s -> IPV4 .matcher (s ).matches (), "not a valid ipv4" )),
87+ Map .entry ("ipv6" , new FormatCheck (s -> IPV6 .matcher (s ).matches (), "not a valid ipv6" )));
7388
7489 private final Function <String , Schema > refResolver ;
7590 private final ConcurrentMap <String , Pattern > compiledPatterns = new ConcurrentHashMap <>();
0 commit comments