Diff

util/jsonschema.lua @ 13867:eabd38507c1d 13.0

util.jsonschema: Fix handling of `false` as schema Schemas can be either a boolean or a table (object) but since it only checked for truthiness, the case of `false` would be handled incorrectly. There seems to be no tests that cover `then` and `else` being `false`, only a couple that check the `if` keyword.
author Kim Alvefur <zash@zash.se>
date Sun, 30 Mar 2025 17:27:23 +0200
parent 13385:72d7830505f0
child 13872:76582d10bc09
line wrap: on
line diff
--- a/util/jsonschema.lua	Fri Apr 18 12:25:06 2025 +0100
+++ b/util/jsonschema.lua	Sun Mar 30 17:27:23 2025 +0200
@@ -188,7 +188,7 @@
 		end
 	end
 
-	if schema["not"] then
+	if schema["not"] ~= nil then
 		if validate(schema["not"], data, root, sloc .. "/not", iloc, errs) then
 			table.insert(errs, mkerr(sloc .. "/not", iloc, "did match subschema"))
 			return false, errs
@@ -197,14 +197,14 @@
 
 	if schema["if"] ~= nil then
 		if validate(schema["if"], data, root, sloc .. "/if", iloc, errs) then
-			if schema["then"] then
+			if schema["then"] ~= nil then
 				if not validate(schema["then"], data, root, sloc .. "/then", iloc, errs) then
 					table.insert(errs, mkerr(sloc .. "/then", iloc, "did not match subschema"))
 					return false, errs
 				end
 			end
 		else
-			if schema["else"] then
+			if schema["else"] ~= nil then
 				if not validate(schema["else"], data, root, sloc .. "/else", iloc, errs) then
 					table.insert(errs, mkerr(sloc .. "/else", iloc, "did not match subschema"))
 					return false, errs