From 0c2cea31ba55de6dab97ca4fc06e27396fb71841 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 13 Jul 2026 14:47:38 +0100 Subject: [PATCH] Break out of loop to allow `result` object to be updated after failing fast --- lib/entry-points.js | 6 +++--- src/json/index.ts | 13 ++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/entry-points.js b/lib/entry-points.js index aefa923c0..083567dfb 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -144556,14 +144556,14 @@ function checkSchema(schema, obj, options = {}, path29 = "") { if (validator.required && !hasKey) { result.valid = false; if (options.failFast) { - return result; + break; } continue; } if (validator.required && (obj[key] === void 0 || obj[key] === null)) { result.valid = false; if (options.failFast) { - return result; + break; } continue; } @@ -144577,7 +144577,7 @@ function checkSchema(schema, obj, options = {}, path29 = "") { if (!checkResult.valid) { result.valid = false; if (options.failFast) { - return result; + break; } continue; } diff --git a/src/json/index.ts b/src/json/index.ts index 2d50ff121..78923f8ba 100644 --- a/src/json/index.ts +++ b/src/json/index.ts @@ -264,9 +264,16 @@ export function checkSchema( path: string = "", ): CheckSchemaResult { const result: CheckSchemaResult = successfulCheckSchema(); + + // Track the set of input keys. We remove keys from this set as we recognise them + // during validation. const inputKeys = new Set(Object.keys(obj)); + + // Track keys that have failed validation, starting with the empty set. const invalidKeys = new Set(); + // Loop through all keys in the object schema and validate that the given object + // satisfies the schema key. for (const [key, validator] of Object.entries(schema)) { const hasKey = key in obj; @@ -282,7 +289,7 @@ export function checkSchema( result.valid = false; if (options.failFast) { - return result; + break; } continue; } @@ -292,7 +299,7 @@ export function checkSchema( result.valid = false; if (options.failFast) { - return result; + break; } continue; } @@ -314,7 +321,7 @@ export function checkSchema( result.valid = false; if (options.failFast) { - return result; + break; } continue; }