Skip to content

Commit

Permalink
Merge pull request #196 from sebastian-toepfer/format_assertion_json-…
Browse files Browse the repository at this point in the history
…pointer

add support for json-pointer format
  • Loading branch information
sebastian-toepfer authored Dec 9, 2024
2 parents 5140221 + 48cd4fc commit 2c42f28
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ final class Formats {
Map.entry("email", Map.entry(5321, "mailbox")),
Map.entry("ipv4", Map.entry(2673, "dotted-quad")),
Map.entry("uuid", Map.entry(4122, "UUID")),
Map.entry("ipv6", Map.entry(4291, "IPv6address"))
Map.entry("ipv6", Map.entry(4291, "IPv6address")),
Map.entry("json-pointer", Map.entry(6901, "json-pointer"))
);

Format findByName(final String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ public final class Rfcs {
)
)
)
),
Map.entry(
6901,
Map.of("json-pointer", new RegExRule(Pattern.compile("^(/([\\x00-.0-}\\x7f-\\u010ffff]|\\~[01])*)*$")))
)
);

Expand Down
6 changes: 6 additions & 0 deletions vocabulary/format-assertion/src/main/resources/rfc/rfc6901
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
json-pointer = *( "/" reference-token )
reference-token = *( unescaped / escaped )
unescaped = %x00-2E / %x30-7D / %x7F-10FFFF
; %x2F ('/') and %x7E ('~') are excluded from 'unescaped'
escaped = "~" ( "0" / "1" )
; representing '~' and '/', respectively
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,10 @@ void should_found_uuidformat() {
assertThat(new Formats().findByName("uuid").applyTo("b7128c5b-eafc-4b6b-9b35-1c9e3dbaabb1"), is(true));
assertThat(new Formats().findByName("uuid").applyTo("b7128c5b-eafc-4b6b-9b35"), is(false));
}

@Test
void should_found_jsonpointerformat() {
assertThat(new Formats().findByName("json-pointer").applyTo("/abc"), is(true));
assertThat(new Formats().findByName("json-pointer:").applyTo("abc"), is(false));
}
}

0 comments on commit 2c42f28

Please sign in to comment.