Skip to content

Commit

Permalink
Merge pull request #190 from sebastian-toepfer/format_assertion_hostname
Browse files Browse the repository at this point in the history
add support for hostname format
  • Loading branch information
sebastian-toepfer authored Dec 6, 2024
2 parents 56b8b59 + e85ac6c commit 776f674
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
final class Formats {

private static final Map<String, Map<Integer, String>> RFCS = Map.of(
"hostname",
Map.of(1123, "hostname"),
"date-time",
Map.of(3339, "date-time"),
"date",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public final class Rfcs {

//create regex with: https://abnf.msweet.org/index.php
private static final Map<Integer, Map<String, Rule>> RULES = Map.ofEntries(
Map.entry(
1123,
Map.of("hostname", new RegExRule(Pattern.compile("(?=\\A[-a-z0-9]{1,63}\\Z)\\A[a-z0-9]+(-[a-z0-9]+)*\\Z")))
),
Map.entry(
2673,
Map.of("dotted-quad", new RegExRule(Pattern.compile("^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,10 @@ void should_found_ipv6Format() {
//ipv4 only -> invalid!
assertThat(new Formats().findByName("ipv6").applyTo("125.158.4589.1"), is(false));
}

@Test
void should_found_hostname() {
assertThat(new Formats().findByName("hostname").applyTo("www"), is(true));
assertThat(new Formats().findByName("hostname").applyTo("bar_baz"), is(false));
}
}

0 comments on commit 776f674

Please sign in to comment.