Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for hostname format #190

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}
Loading