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.
13.0
Kim Alvefur 9 months ago
parent ea99104f0a
commit 052d497dee
  1. 15
      spec/util_jsonschema_spec.lua
  2. 6
      teal-src/prosody/util/jsonschema.tl
  3. 6
      util/jsonschema.lua

@ -31,7 +31,10 @@ local skip = {
["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 @@ local skip = {
["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",
["refRemote.json"] = "DEFINITELY 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",
["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",

@ -315,7 +315,7 @@ local function validate (schema : schema_t, data : any, root : json_schema_objec
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 @@ local function validate (schema : schema_t, data : any, root : json_schema_objec
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;

@ -188,7 +188,7 @@ local function validate(schema, data, root, sloc, iloc, errs)
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 @@ local function validate(schema, data, root, sloc, iloc, errs)
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

Loading…
Cancel
Save