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

[Bug] IRI References with URL encoded '[' and ']' incorrectly fail validation #1050

Closed
4naesthetic opened this issue Jun 6, 2024 · 1 comment · Fixed by #1051
Closed

Comments

@4naesthetic
Copy link
Contributor

IRIs containing %-encoded [ and ] characters incorrectly fail validation due to the following code in the IriFormat and IriReference introduced in #983:

String query = uri.getQuery();
if (query != null) {
// [ and ] must be percent encoded
if (query.indexOf('[') != -1 || query.indexOf(']') != -1) {
return false;
}
}

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:

@justin-tay
Copy link
Contributor

Thanks for the bug report and fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants