Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/PathType.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public enum PathType {
t = t.replace("'", "\\'");
}

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

/**
Expand Down
35 changes: 34 additions & 1 deletion src/test/java/com/networknt/schema/Issue687Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public static Stream<Arguments> appendTokens() {
Arguments.of(PathType.JSON_PATH, "$.foo", "b.ar", "$.foo['b.ar']"),
Arguments.of(PathType.JSON_PATH, "$.foo", "b~ar", "$.foo['b~ar']"),
Arguments.of(PathType.JSON_PATH, "$.foo", "b/ar", "$.foo['b/ar']"),
Arguments.of(PathType.JSON_PATH, "$", "'", "$['\'']"),
Arguments.of(PathType.JSON_PATH, "$", "'", "$['\\'']"),
Arguments.of(PathType.JSON_PATH, "$", "b'ar", "$['b\\'ar']"),
Arguments.of(PathType.JSON_POINTER, "/foo", "bar", "/foo/bar"),
Arguments.of(PathType.JSON_POINTER, "/foo", "b.ar", "/foo/b.ar"),
Arguments.of(PathType.JSON_POINTER, "/foo", "b~ar", "/foo/b~0ar"),
Expand Down Expand Up @@ -122,4 +123,36 @@ void testDoubleQuotes() throws JsonProcessingException {
assertEquals("$['\"']", validationMessages.iterator().next().getPath());
}

@Test
void testSingleQuotes() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
SchemaValidatorsConfig schemaValidatorsConfig = new SchemaValidatorsConfig();
schemaValidatorsConfig.setPathType(PathType.JSON_PATH);
/*
{
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"properties": {
"'": {
"type": "boolean"
}
}
}
*/
JsonSchema schema = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909)
.getSchema(mapper.readTree("{\n" +
" \"$schema\": \"https://json-schema.org/draft/2019-09/schema\",\n" +
" \"type\": \"object\",\n" +
" \"properties\": {\n" +
" \"'\": {\n" +
" \"type\": \"boolean\"\n" +
" }\n" +
" }\n" +
"}"), schemaValidatorsConfig);
// {"\"": 1}
Set<ValidationMessage> validationMessages = schema.validate(mapper.readTree("{\"'\": 1}"));
assertEquals(1, validationMessages.size());
assertEquals("$['\\'']", validationMessages.iterator().next().getPath());
}

}