Skip to content

Commit

Permalink
Trigger bug in "validation loop" handling...
Browse files Browse the repository at this point in the history
It _is_ possible to enter a same schema pointer via two different paths; the
current validation loop detection code only accounts for pointers but not the
path!

Issue java-json-tools#112.

Signed-off-by: Francis Galiegue <[email protected]>
  • Loading branch information
fge committed Oct 18, 2014
1 parent 6e42db5 commit d972889
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,28 @@ public void circularReferencingDuringValidationIsDetected()
assertTrue(true);
}

/*
* Issue #112: what was called a "validation loop" in issue #102 was in fact
* not really one; it is possible to enter the same subschema using
* different paths.
*
* The real thing which must be checked for is a full schema pointer loop.
*/
@Test
public void enteringSamePointerWithDifferentPathsDoesNotThrowException()
throws IOException, ProcessingException
{
final JsonNode node = JsonLoader.fromResource("/other/issue112.json");
final JsonNode schemaNode = node.get("schema");
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final JsonValidator validator = factory.getValidator();

final JsonNode instance = node.get("instance");

assertTrue(validator.validate(schemaNode, instance).isSuccess());
assertTrue(true);
}

public static final class K1Validator
extends AbstractKeywordValidator
{
Expand Down
66 changes: 66 additions & 0 deletions src/test/resources/other/issue112.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"schema":
{
"$schema": "http://json-schema.org/draft-04/schema#",

"definitions": {
"unit-value": {
"type": "object",
"properties": {
"unit": {
"type": "string"
},
"value": {
"type": "number"
}
}
},
"length-unit-value": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/unit-value"
},
{
"properties": {
"unit": {
"type": "string",
"enum": [
"cm",
"in"
]
}
}
}
]
},
"something-containing-unit-value": {
"type": "object",
"properties": {
"unit-value": {
"$ref": "#/definitions/unit-value"
}
},
"required": [ "unit-value"]
}
},

"type": "object",
"allOf": [
{
"$ref": "#/definitions/something-containing-unit-value"
},
{
"properties": {
"unit-value": {
"$ref": "#/definitions/length-unit-value"
}
}
}
]
},
"instance": {
"unit": "cm",
"unit-value": { "unit": "" }
}
}

0 comments on commit d972889

Please sign in to comment.