Repository: networknt/json-schema-validator (java)

Issue:
[Bug] IRI References with URL encoded '[' and ']' incorrectly fail validation
IRIs containing %-encoded `[` and `]` characters incorrectly fail validation due to the following code in the `IriFormat` and `IriReference` introduced in #983:

https://github.com/networknt/json-schema-validator/blob/772832511a9c495ebe6c9ec8908e5505da815e73/src/main/java/com/networknt/schema/format/IriReferenceFormat.java#L17-L23

`uri.getQuery()` decodes the query string, so this scenario fails validation even though `[` and `]` were correctly escaped. Potentially could use `uri.getRawQuery()` instead. This wasn't picked up in the original PR as there was no test case written that would pass when these characters were escaped, only that they were disallowed.

Additional test case that demonstrates the issue:

```
@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()); // Fails
}
```
Test file references:
- https://github.com/networknt/json-schema-validator/blob/master/src/test/java/com/networknt/schema/format/IriReferenceFormatTest.java
- https://github.com/networknt/json-schema-validator/blob/master/src/test/java/com/networknt/schema/format/IriFormatTest.java


Pull request:
Fix for incorrect validation failure for %-encoded '[' and ']' characters
Fixes #1050 

Patch:
diff --git a/src/main/java/com/networknt/schema/format/IriFormat.java b/src/main/java/com/networknt/schema/format/IriFormat.java
index 150741d..7d74429 100644
--- a/src/main/java/com/networknt/schema/format/IriFormat.java
+++ b/src/main/java/com/networknt/schema/format/IriFormat.java
@@ -17,7 +17,7 @@ public class IriFormat extends AbstractRFC3986Format {
                 }
             }
 
-            String query = uri.getQuery();
+            String query = uri.getRawQuery();
             if (query != null) {
                 // [ and ] must be percent encoded
                 if (query.indexOf('[') != -1 || query.indexOf(']') != -1) {
diff --git a/src/main/java/com/networknt/schema/format/IriReferenceFormat.java b/src/main/java/com/networknt/schema/format/IriReferenceFormat.java
index 45f8bd9..aa0a0d0 100644
--- a/src/main/java/com/networknt/schema/format/IriReferenceFormat.java
+++ b/src/main/java/com/networknt/schema/format/IriReferenceFormat.java
@@ -14,7 +14,7 @@ public class IriReferenceFormat extends AbstractRFC3986Format {
                 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) {


Test patch:
diff --git a/src/test/java/com/networknt/schema/format/IriFormatTest.java b/src/test/java/com/networknt/schema/format/IriFormatTest.java
index d8655bf..112f726 100644
--- a/src/test/java/com/networknt/schema/format/IriFormatTest.java
+++ b/src/test/java/com/networknt/schema/format/IriFormatTest.java
@@ -56,6 +56,20 @@ class IriFormatTest {
                 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() {
diff --git a/src/test/java/com/networknt/schema/format/IriReferenceFormatTest.java b/src/test/java/com/networknt/schema/format/IriReferenceFormatTest.java
index 4bbaeda..eba0771 100644
--- a/src/test/java/com/networknt/schema/format/IriReferenceFormatTest.java
+++ b/src/test/java/com/networknt/schema/format/IriReferenceFormatTest.java
@@ -57,6 +57,20 @@ class IriReferenceFormatTest {
         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"