Skip to content

Commit 5b5a192

Browse files
authored
Bug fix for JSON Pointer parsing (#752) (#755)
Co-authored-by: simatosc <[email protected]>
1 parent 2143b54 commit 5b5a192

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/main/java/com/networknt/schema/PathType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public enum PathType {
4141
t = t.replace("'", "\\'");
4242
}
4343

44-
return "['" + token + "']";
44+
return "['" + t + "']";
4545
}, (index) -> "[" + index + "]"),
4646

4747
/**

src/test/java/com/networknt/schema/Issue687Test.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public static Stream<Arguments> appendTokens() {
3737
Arguments.of(PathType.JSON_PATH, "$.foo", "b.ar", "$.foo['b.ar']"),
3838
Arguments.of(PathType.JSON_PATH, "$.foo", "b~ar", "$.foo['b~ar']"),
3939
Arguments.of(PathType.JSON_PATH, "$.foo", "b/ar", "$.foo['b/ar']"),
40-
Arguments.of(PathType.JSON_PATH, "$", "'", "$['\'']"),
40+
Arguments.of(PathType.JSON_PATH, "$", "'", "$['\\'']"),
41+
Arguments.of(PathType.JSON_PATH, "$", "b'ar", "$['b\\'ar']"),
4142
Arguments.of(PathType.JSON_POINTER, "/foo", "bar", "/foo/bar"),
4243
Arguments.of(PathType.JSON_POINTER, "/foo", "b.ar", "/foo/b.ar"),
4344
Arguments.of(PathType.JSON_POINTER, "/foo", "b~ar", "/foo/b~0ar"),
@@ -122,4 +123,36 @@ void testDoubleQuotes() throws JsonProcessingException {
122123
assertEquals("$['\"']", validationMessages.iterator().next().getPath());
123124
}
124125

126+
@Test
127+
void testSingleQuotes() throws JsonProcessingException {
128+
ObjectMapper mapper = new ObjectMapper();
129+
SchemaValidatorsConfig schemaValidatorsConfig = new SchemaValidatorsConfig();
130+
schemaValidatorsConfig.setPathType(PathType.JSON_PATH);
131+
/*
132+
{
133+
"$schema": "https://json-schema.org/draft/2019-09/schema",
134+
"type": "object",
135+
"properties": {
136+
"'": {
137+
"type": "boolean"
138+
}
139+
}
140+
}
141+
*/
142+
JsonSchema schema = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909)
143+
.getSchema(mapper.readTree("{\n" +
144+
" \"$schema\": \"https://json-schema.org/draft/2019-09/schema\",\n" +
145+
" \"type\": \"object\",\n" +
146+
" \"properties\": {\n" +
147+
" \"'\": {\n" +
148+
" \"type\": \"boolean\"\n" +
149+
" }\n" +
150+
" }\n" +
151+
"}"), schemaValidatorsConfig);
152+
// {"\"": 1}
153+
Set<ValidationMessage> validationMessages = schema.validate(mapper.readTree("{\"'\": 1}"));
154+
assertEquals(1, validationMessages.size());
155+
assertEquals("$['\\'']", validationMessages.iterator().next().getPath());
156+
}
157+
125158
}

0 commit comments

Comments
 (0)