Skip to content

[1.0.81] JSON Path does not handle all special characters #750

@slisaasquatch

Description

@slisaasquatch

Here's a code example to reproduce the issue:

public static void main(String[] args) throws Exception {
	final ObjectMapper mapper = new ObjectMapper();
	final SchemaValidatorsConfig schemaValidatorsConfig = new SchemaValidatorsConfig();
	schemaValidatorsConfig.setPathType(PathType.JSON_PATH);
	/*
		{
			"$schema": "https://json-schema.org/draft/2019-09/schema",
			"type": "object",
			"properties": {
				"\"": {
					"type": "boolean"
				}
			}
		}
	 */
	final 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}
	final Set<ValidationMessage> validationMessages = schema.validate(mapper.readTree("{\"\\\"\": 1}"));
	for (ValidationMessage validationMessage : validationMessages) {
		// Prints $["""]
		System.out.println(validationMessage.getPath());
	}
}

If the field name has " (and potentially other special characters), the JSON Path generated is invalid.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions