From 99ff93edd777cd5a602b06f04ea4b398ee3195f8 Mon Sep 17 00:00:00 2001 From: Sebastian Toepfer <61313468+sebastian-toepfer@users.noreply.github.com> Date: Wed, 4 Dec 2024 21:22:23 +0100 Subject: [PATCH] update abnf and regex for rfc4291 --- .../vocabulary/formatassertion/Formats.java | 2 +- .../formatassertion/rfc/Rfc4291.java | 29 ++++++++++++++---- .../src/main/resources/rfc/rfc4291 | 30 ++++++++++++++----- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/Formats.java b/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/Formats.java index 97e709f..d3b2b9c 100644 --- a/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/Formats.java +++ b/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/Formats.java @@ -48,7 +48,7 @@ final class Formats { Stream.of( new RfcBasedFormat("email", new Rfc5321(), "mailbox"), new RfcBasedFormat("ipv4", new Rfc2673(), "dotted-quad"), - new RfcBasedFormat("ipv6", new Rfc4291(), "address") + new RfcBasedFormat("ipv6", new Rfc4291(), "IPv6address") ) ) .map(Format.class::cast) diff --git a/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/rfc/Rfc4291.java b/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/rfc/Rfc4291.java index 88e6853..6cd42be 100644 --- a/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/rfc/Rfc4291.java +++ b/vocabulary/format-assertion/src/main/java/io/github/sebastiantoepfer/jsonschema/vocabulary/formatassertion/rfc/Rfc4291.java @@ -30,13 +30,30 @@ public final class Rfc4291 implements Rfc { private static final Map RULES = Map.of( - "address", + "IPv6address", Pattern.comp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d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|" + + "25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5]))|" + + "(([0-9A-Fa-f]{1,4}\\:){0,5}[0-9A-Fa-f]{1,4})?\\:\\:[0-9A-Fa-f]{1,4}|(([0-9A-Fa-f]{1,4}\\:){0,6}" + + "[0-9A-Fa-f]{1,4})?\\:\\:)$" ) ); diff --git a/vocabulary/format-assertion/src/main/resources/rfc/rfc4291 b/vocabulary/format-assertion/src/main/resources/rfc/rfc4291 index e561c59..1528334 100644 --- a/vocabulary/format-assertion/src/main/resources/rfc/rfc4291 +++ b/vocabulary/format-assertion/src/main/resources/rfc/rfc4291 @@ -1,7 +1,23 @@ -; selfmade :( -> not effectiv -dotted-quad = decbyte "." decbyte "." decbyte "." decbyte -decbyte = 1*3DIGIT -address = (hexbytes 7(":" hexbytes) ) / *(hexbytes *5(":" hexbytes)) zeros *(hexbytes *5(":" hexbytes)) / ((((hexbytes 5(":" hexbytes) ) ":") / *(hexbytes *4(":" hexbytes)) zeros *(hexbytes *4(":" hexbytes))) dotted-quad) -zeros = "::" -hexbytes = 1*4hexValue -hexValue = DIGIT / %x41-46 / %x61-66 +IPv6address = 6( h16 ":" ) ls32 + / "::" 5( h16 ":" ) ls32 + / [ h16 ] "::" 4( h16 ":" ) ls32 + / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32 + / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32 + / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32 + / [ *4( h16 ":" ) h16 ] "::" ls32 + / [ *5( h16 ":" ) h16 ] "::" h16 + / [ *6( h16 ":" ) h16 ] "::" + +ls32 = ( h16 ":" h16 ) / IPv4address + ; least-significant 32 bits of address + +h16 = 1*4HEXDIG + ; 16 bits of address represented in hexadecimal + +IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet + +dec-octet = DIGIT ; 0-9 + / %x31-39 DIGIT ; 10-99 + / "1" 2DIGIT ; 100-199 + / "2" %x30-34 DIGIT ; 200-249 + / "25" %x30-35 ; 250-255