Skip to content

Commit d972889

Browse files
committed
Trigger bug in "validation loop" handling...
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 #112. Signed-off-by: Francis Galiegue <[email protected]>
1 parent 6e42db5 commit d972889

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

src/test/java/com/github/fge/jsonschema/processors/validation/ValidationProcessorTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,28 @@ public void circularReferencingDuringValidationIsDetected()
157157
assertTrue(true);
158158
}
159159

160+
/*
161+
* Issue #112: what was called a "validation loop" in issue #102 was in fact
162+
* not really one; it is possible to enter the same subschema using
163+
* different paths.
164+
*
165+
* The real thing which must be checked for is a full schema pointer loop.
166+
*/
167+
@Test
168+
public void enteringSamePointerWithDifferentPathsDoesNotThrowException()
169+
throws IOException, ProcessingException
170+
{
171+
final JsonNode node = JsonLoader.fromResource("/other/issue112.json");
172+
final JsonNode schemaNode = node.get("schema");
173+
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
174+
final JsonValidator validator = factory.getValidator();
175+
176+
final JsonNode instance = node.get("instance");
177+
178+
assertTrue(validator.validate(schemaNode, instance).isSuccess());
179+
assertTrue(true);
180+
}
181+
160182
public static final class K1Validator
161183
extends AbstractKeywordValidator
162184
{
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"schema":
3+
{
4+
"$schema": "http://json-schema.org/draft-04/schema#",
5+
6+
"definitions": {
7+
"unit-value": {
8+
"type": "object",
9+
"properties": {
10+
"unit": {
11+
"type": "string"
12+
},
13+
"value": {
14+
"type": "number"
15+
}
16+
}
17+
},
18+
"length-unit-value": {
19+
"type": "object",
20+
"allOf": [
21+
{
22+
"$ref": "#/definitions/unit-value"
23+
},
24+
{
25+
"properties": {
26+
"unit": {
27+
"type": "string",
28+
"enum": [
29+
"cm",
30+
"in"
31+
]
32+
}
33+
}
34+
}
35+
]
36+
},
37+
"something-containing-unit-value": {
38+
"type": "object",
39+
"properties": {
40+
"unit-value": {
41+
"$ref": "#/definitions/unit-value"
42+
}
43+
},
44+
"required": [ "unit-value"]
45+
}
46+
},
47+
48+
"type": "object",
49+
"allOf": [
50+
{
51+
"$ref": "#/definitions/something-containing-unit-value"
52+
},
53+
{
54+
"properties": {
55+
"unit-value": {
56+
"$ref": "#/definitions/length-unit-value"
57+
}
58+
}
59+
}
60+
]
61+
},
62+
"instance": {
63+
"unit": "cm",
64+
"unit-value": { "unit": "" }
65+
}
66+
}

0 commit comments

Comments
 (0)