Changeset

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
parents 13854:0b01f40df0f9
children 13868:14b52f217f7a
files spec/util_jsonschema_spec.lua teal-src/prosody/util/jsonschema.tl util/jsonschema.lua
diffstat 3 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/spec/util_jsonschema_spec.lua	Fri Apr 18 12:25:06 2025 +0100
+++ b/spec/util_jsonschema_spec.lua	Sun Mar 30 17:27:23 2025 +0200
@@ -31,7 +31,10 @@
 	["patternProperties.json"] = "NYI",
 	["properties.json:1:2"] = "NYI",
 	["properties.json:1:3"] = "NYI",
+	["propertyNames.json:1:1"] = "NYI",
 	["ref.json:0:3"] = "util.jsonpointer recursive issue?",
+	["ref.json:3:2"] = "FIXME investigate, util.jsonpath issue?",
+	["ref.json:6:1"] = "NYI",
 	["ref.json:11"] = "NYI",
 	["ref.json:12:1"] = "FIXME",
 	["ref.json:13"] = "NYI",
@@ -41,28 +44,26 @@
 	["ref.json:17"] = "NYI",
 	["ref.json:18"] = "NYI",
 	["ref.json:19"] = "NYI",
+	["ref.json:20"] = "NYI",
+	["ref.json:25"] = "NYI",
 	["ref.json:26"] = "NYI",
 	["ref.json:27"] = "NYI",
 	["ref.json:28"] = "NYI",
-	["ref.json:3:2"] = "FIXME investigate, util.jsonpath issue?",
-	["required.json:4"] = "JavaScript specific and distinguishing objects from arrays",
-	["ref.json:6:1"] = "NYI",
-	["ref.json:20"] = "NYI",
-	["ref.json:25"] = "NYI",
 	["ref.json:29"] = "NYI",
 	["ref.json:30"] = "NYI",
 	["ref.json:31"] = "NYI",
 	["ref.json:32"] = "NYI",
 	["not.json:6"] = "NYI",
+	["required.json:0:2"] = "distinguishing objects from arrays",
+	["required.json:4"] = "JavaScript specific and distinguishing objects from arrays",
+	["not.json:8:0"] = "NYI",
 	["refRemote.json"] = "DEFINITELY NYI",
-	["required.json:0:2"] = "distinguishing objects from arrays",
 	["type.json:0:1"] = "1.0 is not an integer!",
 	["type.json:3:4"] = "distinguishing objects from arrays",
 	["type.json:3:6"] = "null is weird",
 	["type.json:4:3"] = "distinguishing objects from arrays",
 	["type.json:4:6"] = "null is weird",
 	["type.json:9:4"] = "null is weird",
-	["type.json:9:6"] = "null is weird",
 	["unevaluatedItems.json"] = "NYI",
 	["unevaluatedProperties.json"] = "NYI",
 	["uniqueItems.json:0:10"] = "deepcompare",
--- a/teal-src/prosody/util/jsonschema.tl	Fri Apr 18 12:25:06 2025 +0100
+++ b/teal-src/prosody/util/jsonschema.tl	Sun Mar 30 17:27:23 2025 +0200
@@ -315,7 +315,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;
@@ -324,14 +324,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;
--- 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