Skip to content

Commit 302ef08

Browse files
committed
Fixed a error that the $ref has to start with a '#' but it only checks if it's one '#' and in the core meta schema the path[0] will be '##' as the schema ends with a #.
Adding a test for validating the http://json-schema.org/draft-04/schema# schema wich fails with a StackOverFlow Exception due to a recursive loop when downloading the schema.
1 parent 2afd11f commit 302ef08

File tree

3 files changed

+189
-1
lines changed

3 files changed

+189
-1
lines changed

core/src/main/java/org/everit/json/schema/loader/internal/JSONPointer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public QueryResult query() {
153153
return new QueryResult(document, document);
154154
}
155155
String[] path = fragment.split("/");
156-
if (!"#".equals(path[0])) {
156+
if ( path[0] == null || !path[0].startsWith("#")) {
157157
throw new IllegalArgumentException("JSON pointers must start with a '#'");
158158
}
159159
Object current = document;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (C) 2011 Everit Kft. (http://www.everit.org)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.everit.json.schema;
17+
18+
import org.everit.json.schema.loader.SchemaLoader;
19+
import org.json.JSONObject;
20+
import org.json.JSONTokener;
21+
import org.junit.Test;
22+
23+
public class MetaSchemaTest {
24+
25+
@Test
26+
public void validateMetaSchema() {
27+
28+
JSONObject jsonSchema = new JSONObject(new JSONTokener(
29+
MetaSchemaTest.class.getResourceAsStream("/org/everit/jsonvalidator/json-schema-draft-04.json")));
30+
31+
JSONObject jsonSubject = new JSONObject(new JSONTokener(
32+
MetaSchemaTest.class.getResourceAsStream("/org/everit/jsonvalidator/json-schema-draft-04.json")));
33+
34+
Schema schema = SchemaLoader.load(jsonSchema);
35+
schema.validate(jsonSubject);
36+
}
37+
38+
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
{
2+
"id": "http://json-schema.org/draft-04/schema#",
3+
"$schema": "http://json-schema.org/draft-04/schema#",
4+
"description": "Core schema meta-schema",
5+
"definitions": {
6+
"schemaArray": {
7+
"type": "array",
8+
"minItems": 1,
9+
"items": { "$ref": "#" }
10+
},
11+
"positiveInteger": {
12+
"type": "integer",
13+
"minimum": 0
14+
},
15+
"positiveIntegerDefault0": {
16+
"allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
17+
},
18+
"simpleTypes": {
19+
"enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
20+
},
21+
"stringArray": {
22+
"type": "array",
23+
"items": { "type": "string" },
24+
"minItems": 1,
25+
"uniqueItems": true
26+
}
27+
},
28+
"type": "object",
29+
"properties": {
30+
"id": {
31+
"type": "string",
32+
"format": "uri"
33+
},
34+
"$schema": {
35+
"type": "string",
36+
"format": "uri"
37+
},
38+
"title": {
39+
"type": "string"
40+
},
41+
"description": {
42+
"type": "string"
43+
},
44+
"default": {},
45+
"multipleOf": {
46+
"type": "number",
47+
"minimum": 0,
48+
"exclusiveMinimum": true
49+
},
50+
"maximum": {
51+
"type": "number"
52+
},
53+
"exclusiveMaximum": {
54+
"type": "boolean",
55+
"default": false
56+
},
57+
"minimum": {
58+
"type": "number"
59+
},
60+
"exclusiveMinimum": {
61+
"type": "boolean",
62+
"default": false
63+
},
64+
"maxLength": { "$ref": "#/definitions/positiveInteger" },
65+
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
66+
"pattern": {
67+
"type": "string",
68+
"format": "regex"
69+
},
70+
"additionalItems": {
71+
"anyOf": [
72+
{ "type": "boolean" },
73+
{ "$ref": "#" }
74+
],
75+
"default": {}
76+
},
77+
"items": {
78+
"anyOf": [
79+
{ "$ref": "#" },
80+
{ "$ref": "#/definitions/schemaArray" }
81+
],
82+
"default": {}
83+
},
84+
"maxItems": { "$ref": "#/definitions/positiveInteger" },
85+
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
86+
"uniqueItems": {
87+
"type": "boolean",
88+
"default": false
89+
},
90+
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
91+
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
92+
"required": { "$ref": "#/definitions/stringArray" },
93+
"additionalProperties": {
94+
"anyOf": [
95+
{ "type": "boolean" },
96+
{ "$ref": "#" }
97+
],
98+
"default": {}
99+
},
100+
"definitions": {
101+
"type": "object",
102+
"additionalProperties": { "$ref": "#" },
103+
"default": {}
104+
},
105+
"properties": {
106+
"type": "object",
107+
"additionalProperties": { "$ref": "#" },
108+
"default": {}
109+
},
110+
"patternProperties": {
111+
"type": "object",
112+
"additionalProperties": { "$ref": "#" },
113+
"default": {}
114+
},
115+
"dependencies": {
116+
"type": "object",
117+
"additionalProperties": {
118+
"anyOf": [
119+
{ "$ref": "#" },
120+
{ "$ref": "#/definitions/stringArray" }
121+
]
122+
}
123+
},
124+
"enum": {
125+
"type": "array",
126+
"minItems": 1,
127+
"uniqueItems": true
128+
},
129+
"type": {
130+
"anyOf": [
131+
{ "$ref": "#/definitions/simpleTypes" },
132+
{
133+
"type": "array",
134+
"items": { "$ref": "#/definitions/simpleTypes" },
135+
"minItems": 1,
136+
"uniqueItems": true
137+
}
138+
]
139+
},
140+
"allOf": { "$ref": "#/definitions/schemaArray" },
141+
"anyOf": { "$ref": "#/definitions/schemaArray" },
142+
"oneOf": { "$ref": "#/definitions/schemaArray" },
143+
"not": { "$ref": "#" }
144+
},
145+
"dependencies": {
146+
"exclusiveMaximum": [ "maximum" ],
147+
"exclusiveMinimum": [ "minimum" ]
148+
},
149+
"default": {}
150+
}

0 commit comments

Comments
 (0)