Skip to content
Open
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
9 changes: 5 additions & 4 deletions src/json-schema-errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ async function toAbsoluteKeywordLocation(schema, keywordLocation) {
/** @type API.evaluateSchema */
export const evaluateSchema = (schemaLocation, instance, context) => {
const instanceLocation = Instance.uri(instance);
// The error index stores property name locations ("#*/foo") without the "*"
const indexedInstanceLocation = instanceLocation.replace(/^#\*/, "#");

let valid = true;
/** @type API.NormalizedOutput */
Expand All @@ -137,7 +139,7 @@ export const evaluateSchema = (schemaLocation, instance, context) => {

const schemaNode = context.ast[schemaLocation];
if (typeof schemaNode === "boolean") {
const isSchemaValid = getReportedValidity(schemaLocation, instanceLocation, context);
const isSchemaValid = getReportedValidity(schemaLocation, indexedInstanceLocation, context);
if (schemaNode === false && isSchemaValid !== true) {
valid = false;
output[instanceLocation] = {
Expand All @@ -159,8 +161,7 @@ export const evaluateSchema = (schemaLocation, instance, context) => {

const validationKeyword = getKeyword(keywordUri);

const keywordInstanceLocation = instanceLocation.replace(/^#\*/, "#");
let isKeywordValid = getReportedValidity(keywordLocation, keywordInstanceLocation, context);
let isKeywordValid = getReportedValidity(keywordLocation, indexedInstanceLocation, context);

/** @type API.EvaluationContext */
const keywordContext = {
Expand All @@ -178,7 +179,7 @@ export const evaluateSchema = (schemaLocation, instance, context) => {

const keywordOutput = keyword.evaluate?.(keywordValue, instance, keywordContext);

const isReported = context.errorIndex[keywordLocation]?.[keywordInstanceLocation] !== undefined;
const isReported = context.errorIndex[keywordLocation]?.[indexedInstanceLocation] !== undefined;
if (validationKeyword.simpleApplicator && !isReported && keywordOutput?.some((suboutput) => getValidity(suboutput) === false)) {
isKeywordValid = false;
}
Expand Down
87 changes: 87 additions & 0 deletions src/test-suite/tests/propertyNames.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,93 @@
"instance": 42,
"errors": []
},
{
"description": "propertyNames false",
"compatibility": "6",
"schema": {
"propertyNames": false
},
"instance": { "foo": 42 },
"errors": [
{
"messageId": "boolean-schema-message",
"instanceLocation": "#*/foo",
"schemaLocations": ["#/propertyNames"]
}
]
},
{
"description": "propertyNames with a false schema in allOf",
"compatibility": "6",
"schema": {
"propertyNames": { "allOf": [false] }
},
"instance": { "foo": 42 },
"errors": [
{
"messageId": "boolean-schema-message",
"instanceLocation": "#*/foo",
"schemaLocations": ["#/propertyNames/allOf/0"]
}
]
},
{
"description": "propertyNames with a $ref to a false schema",
"compatibility": "6",
"schema": {
"propertyNames": { "$ref": "#/$defs/never" },
"$defs": {
"never": false
}
},
"instance": { "foo": 42 },
"errors": [
{
"messageId": "boolean-schema-message",
"instanceLocation": "#*/foo",
"schemaLocations": ["#/$defs/never"]
}
]
},
{
"description": "propertyNames false in anyOf",
"compatibility": "6",
"schema": {
"anyOf": [
{ "propertyNames": false },
{ "type": "string" }
]
},
"instance": { "foo": 42 },
"errors": [
{
"messageId": "anyOf-message",
"alternatives": [
[
{
"messageId": "boolean-schema-message",
"instanceLocation": "#*/foo",
"schemaLocations": ["#/anyOf/0/propertyNames"]
}
],
[
{
"messageId": "type-message",
"messageParams": {
"count": 1,
"type": "string",
"expectedTypes": { "or": ["string"] }
},
"instanceLocation": "#",
"schemaLocations": ["#/anyOf/1/type"]
}
]
],
"instanceLocation": "#",
"schemaLocations": ["#/anyOf"]
}
]
},
{
"description": "propertyNames pass",
"schema": {
Expand Down
Loading