Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/main/java/com/networknt/schema/utils/RFC5892.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ public static boolean isValid(String value) {
// RFC 5892 calls each segment in a host name a label. They are separated by all the recognized label separators.
String[] labels = value.split(LABEL_SEPARATOR_REGEX);
for (String label : labels) {
if (label.isEmpty()) continue; // A DNS entry may contain a trailing '.'.
// String.split() drops trailing empty strings, so a trailing '.' never
// produces an empty label here. A leading or interior empty label
// (e.g. ".example" or "a..b") is invalid.
if (label.isEmpty()) return false;
Comment on lines 107 to +111

String unicode = label;
if (isACE(label)) {
Expand Down
16 changes: 16 additions & 0 deletions src/test/java/com/networknt/schema/FormatValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,20 @@ void draft7DisableFormat() {
});
assertEquals(0, messages.size());
}

@Test
void idnHostnameRejectsEmptyLabels() {
String schemaData = "{\"$schema\":\"https://json-schema.org/draft/2020-12/schema\",\"format\":\"idn-hostname\"}";
Schema schema = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_2020_12).getSchema(schemaData);
// A leading or interior empty label (a leading dot, or two adjacent dots) is invalid.
assertFalse(schema.validate("\".example\"", InputFormat.JSON,
ec -> ec.executionConfig(c -> c.formatAssertionsEnabled(true))).isEmpty());
assertFalse(schema.validate("\"a..b\"", InputFormat.JSON,
ec -> ec.executionConfig(c -> c.formatAssertionsEnabled(true))).isEmpty());
Comment on lines +228 to +232
// Ordinary host names remain valid.
assertTrue(schema.validate("\"example\"", InputFormat.JSON,
ec -> ec.executionConfig(c -> c.formatAssertionsEnabled(true))).isEmpty());
assertTrue(schema.validate("\"sub.example.com\"", InputFormat.JSON,
ec -> ec.executionConfig(c -> c.formatAssertionsEnabled(true))).isEmpty());
}
}
Loading