Skip to content

Commit 61fa3a5

Browse files
authored
Fix idn-hostname format and update json schema test suite (#1191)
1 parent 2d9c327 commit 61fa3a5

File tree

126 files changed

+3381
-970
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+3381
-970
lines changed

src/main/java/com/networknt/schema/format/IdnHostnameFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
public class IdnHostnameFormat implements Format {
1111
@Override
1212
public boolean matches(ExecutionContext executionContext, String value) {
13-
if (null == value || value.isEmpty()) return true;
13+
if (null == value) return true;
1414
return RFC5892.isValid(value);
1515
}
1616

src/main/java/com/networknt/schema/utils/RFC5892.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,22 @@ private static boolean testAllowedCharacter(String s, int i) {
8888
&& !isContextJ(c) && !isContextO(c); // RFC 5891 4.2.3.3. Contextual Rules
8989
}
9090

91+
/**
92+
* Whenever dots are used as label separators, the following characters MUST be
93+
* recognized as dots: U+002E (full stop), U+3002 (ideographic full stop),
94+
* U+FF0E (fullwidth full stop), U+FF61 (halfwidth ideographic full stop)
95+
*/
96+
private static String LABEL_SEPARATOR_REGEX = "[\\.\\u3002\\uff0e\\uff61]";
97+
9198
public static boolean isValid(String value) {
92-
// RFC 5892 calls each segment in a host name a label. They are separated by '.'.
93-
String[] labels = value.split("\\.");
99+
if ("".equals(value)) {
100+
return false; // empty string should fail
101+
}
102+
if (value.length() == 1 && value.matches(LABEL_SEPARATOR_REGEX)) {
103+
return false; // single label separator should fail
104+
}
105+
// RFC 5892 calls each segment in a host name a label. They are separated by all the recognized label separators.
106+
String[] labels = value.split(LABEL_SEPARATOR_REGEX);
94107
for (String label : labels) {
95108
if (label.isEmpty()) continue; // A DNS entry may contain a trailing '.'.
96109

src/test/java/com/networknt/schema/UriMappingTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class UriMappingTest {
4343
*/
4444
@Test
4545
void testBuilderUriMappingUri() throws IOException {
46-
URL mappings = UriMappingTest.class.getResource("/draft4/extra/uri_mapping/uri-mapping.json");
46+
URL mappings = UriMappingTest.class.getResource("/uri_mapping/uri-mapping.json");
4747
JsonMetaSchema draftV4 = JsonMetaSchema.getV4();
4848
Builder builder = JsonSchemaFactory.builder()
4949
.defaultMetaSchemaIri(draftV4.getIri())
@@ -81,7 +81,7 @@ void testBuilderExampleMappings() throws IOException {
8181
} catch (Exception ex) {
8282
fail("Unexpected exception thrown", ex);
8383
}
84-
URL mappings = UriMappingTest.class.getResource("/draft4/extra/uri_mapping/invalid-schema-uri.json");
84+
URL mappings = UriMappingTest.class.getResource("/uri_mapping/invalid-schema-uri.json");
8585
JsonMetaSchema draftV4 = JsonMetaSchema.getV4();
8686
Builder builder = JsonSchemaFactory.builder()
8787
.defaultMetaSchemaIri(draftV4.getIri())
@@ -100,7 +100,7 @@ void testBuilderExampleMappings() throws IOException {
100100
*/
101101
@Test
102102
void testValidatorConfigUriMappingUri() throws IOException {
103-
URL mappings = UriMappingTest.class.getResource("/draft4/extra/uri_mapping/uri-mapping.json");
103+
URL mappings = UriMappingTest.class.getResource("/uri_mapping/uri-mapping.json");
104104
JsonSchemaFactory instance = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4))
105105
.schemaMappers(schemaMappers -> schemaMappers.add(getUriMappingsFromUrl(mappings))).build();
106106
JsonSchema schema = instance.getSchema(SchemaLocation.of(
@@ -118,7 +118,7 @@ void testValidatorConfigUriMappingUri() throws IOException {
118118
*/
119119
@Test
120120
void testValidatorConfigExampleMappings() throws IOException {
121-
URL mappings = UriMappingTest.class.getResource("/draft4/extra/uri_mapping/invalid-schema-uri.json");
121+
URL mappings = UriMappingTest.class.getResource("/uri_mapping/invalid-schema-uri.json");
122122
JsonSchemaFactory instance = JsonSchemaFactory
123123
.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4)).build();
124124
SchemaValidatorsConfig config = SchemaValidatorsConfig.builder().build();
@@ -145,11 +145,11 @@ void testValidatorConfigExampleMappings() throws IOException {
145145

146146
@Test
147147
void testMappingsForRef() throws IOException {
148-
URL mappings = UriMappingTest.class.getResource("/draft4/extra/uri_mapping/schema-with-ref-mapping.json");
148+
URL mappings = UriMappingTest.class.getResource("/uri_mapping/schema-with-ref-mapping.json");
149149
JsonSchemaFactory instance = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4))
150150
.schemaMappers(schemaMappers -> schemaMappers.add(getUriMappingsFromUrl(mappings))).build();
151151
SchemaValidatorsConfig config = SchemaValidatorsConfig.builder().build();
152-
JsonSchema schema = instance.getSchema(SchemaLocation.of("resource:draft4/extra/uri_mapping/schema-with-ref.json"),
152+
JsonSchema schema = instance.getSchema(SchemaLocation.of("resource:uri_mapping/schema-with-ref.json"),
153153
config);
154154
assertEquals(0, schema.validate(mapper.readTree("[]")).size());
155155
}

src/test/java/com/networknt/schema/suite/TestCase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.networknt.schema.suite;
22

33
import com.fasterxml.jackson.annotation.JsonCreator;
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
45
import com.fasterxml.jackson.annotation.JsonProperty;
56
import com.fasterxml.jackson.databind.JsonNode;
67

@@ -12,6 +13,7 @@
1213
* An individual test case, containing multiple testSpecs of a single schema's
1314
* behavior
1415
*/
16+
@JsonIgnoreProperties(ignoreUnknown = true) // ignore specification in additionalProperties.json
1517
public class TestCase {
1618

1719
/**
File renamed without changes.

src/test/resources/draft4/extra/uri_mapping/invalid-schema-uri.json renamed to src/test/resources/uri_mapping/invalid-schema-uri.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
},
66
{
77
"publicURL": "http://example.com/invalid/schema/url",
8-
"localURL": "resource:/draft4/extra/uri_mapping/example-schema.json"
8+
"localURL": "resource:/uri_mapping/example-schema.json"
99
},
1010
{
1111
"publicURL": "https://example.com/invalid/schema/url",
12-
"localURL": "resource:/draft4/extra/uri_mapping/example-schema.json"
12+
"localURL": "resource:/uri_mapping/example-schema.json"
1313
}
1414

1515
]

src/test/resources/draft4/extra/uri_mapping/schema-with-ref-mapping.json renamed to src/test/resources/uri_mapping/schema-with-ref-mapping.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
},
66
{
77
"publicURL": "http://example.com/invalid/schema/url",
8-
"localURL": "resource:/draft4/extra/uri_mapping/example-schema.json"
8+
"localURL": "resource:/uri_mapping/example-schema.json"
99
}
1010
]
File renamed without changes.

src/test/resources/draft4/extra/uri_mapping/uri-mapping.json renamed to src/test/resources/uri_mapping/uri-mapping.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
},
66
{
77
"publicURL": "https://raw.githubusercontent.com/networknt/json-schema-validator/master/src/test/resources/draft4/extra/uri_mapping/uri-mapping.schema.json",
8-
"localURL": "resource:/draft4/extra/uri_mapping/uri-mapping.schema.json"
8+
"localURL": "resource:/uri_mapping/uri-mapping.schema.json"
99
}
1010
]
File renamed without changes.

0 commit comments

Comments
 (0)