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

Fix for incorrect validation failure for %-encoded '[' and ']' characters #1051

Merged
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
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/format/IriFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected boolean validate(URI uri) {
}
}

String query = uri.getQuery();
String query = uri.getRawQuery();
if (query != null) {
// [ and ] must be percent encoded
if (query.indexOf('[') != -1 || query.indexOf(']') != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ protected boolean validate(URI uri) {
return false;
}
}
String query = uri.getQuery();
String query = uri.getRawQuery();
if (query != null) {
// [ and ] must be percent encoded
if (query.indexOf('[') != -1 || query.indexOf(']') != -1) {
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/networknt/schema/format/IriFormatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ void queryWithBracketsShouldFail() {
InputFormat.JSON);
assertFalse(messages.isEmpty());
}

@Test
void queryWithEncodedBracketsShouldPass() {
String schemaData = "{\r\n"
+ " \"format\": \"iri\"\r\n"
+ "}";

SchemaValidatorsConfig config = new SchemaValidatorsConfig();
config.setFormatAssertionsEnabled(true);
JsonSchema schema = JsonSchemaFactory.getInstance(VersionFlag.V202012).getSchema(schemaData, config);
Set<ValidationMessage> messages = schema.validate("\"https://test.com/assets/product.pdf?filter%5Btest%5D=1\"",
InputFormat.JSON);
assertTrue(messages.isEmpty());
}

@Test
void iriShouldPass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ void queryWithBracketsShouldFail() {
assertFalse(messages.isEmpty());
}

@Test
void queryWithEncodedBracketsShouldPass() {
String schemaData = "{\r\n"
+ " \"format\": \"iri-reference\"\r\n"
+ "}";

SchemaValidatorsConfig config = new SchemaValidatorsConfig();
config.setFormatAssertionsEnabled(true);
JsonSchema schema = JsonSchemaFactory.getInstance(VersionFlag.V202012).getSchema(schemaData, config);
Set<ValidationMessage> messages = schema.validate("\"https://test.com/assets/product.pdf?filter%5Btest%5D=1\"",
InputFormat.JSON);
assertTrue(messages.isEmpty());
}

@Test
void iriShouldPass() {
String schemaData = "{\r\n"
Expand Down