Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
13854:0b01f40df0f9 | 13867:eabd38507c1d |
---|---|
186 table.insert(errs, mkerr(sloc .. "/anyOf", iloc, "did not match any subschema")) | 186 table.insert(errs, mkerr(sloc .. "/anyOf", iloc, "did not match any subschema")) |
187 return false, errs | 187 return false, errs |
188 end | 188 end |
189 end | 189 end |
190 | 190 |
191 if schema["not"] then | 191 if schema["not"] ~= nil then |
192 if validate(schema["not"], data, root, sloc .. "/not", iloc, errs) then | 192 if validate(schema["not"], data, root, sloc .. "/not", iloc, errs) then |
193 table.insert(errs, mkerr(sloc .. "/not", iloc, "did match subschema")) | 193 table.insert(errs, mkerr(sloc .. "/not", iloc, "did match subschema")) |
194 return false, errs | 194 return false, errs |
195 end | 195 end |
196 end | 196 end |
197 | 197 |
198 if schema["if"] ~= nil then | 198 if schema["if"] ~= nil then |
199 if validate(schema["if"], data, root, sloc .. "/if", iloc, errs) then | 199 if validate(schema["if"], data, root, sloc .. "/if", iloc, errs) then |
200 if schema["then"] then | 200 if schema["then"] ~= nil then |
201 if not validate(schema["then"], data, root, sloc .. "/then", iloc, errs) then | 201 if not validate(schema["then"], data, root, sloc .. "/then", iloc, errs) then |
202 table.insert(errs, mkerr(sloc .. "/then", iloc, "did not match subschema")) | 202 table.insert(errs, mkerr(sloc .. "/then", iloc, "did not match subschema")) |
203 return false, errs | 203 return false, errs |
204 end | 204 end |
205 end | 205 end |
206 else | 206 else |
207 if schema["else"] then | 207 if schema["else"] ~= nil then |
208 if not validate(schema["else"], data, root, sloc .. "/else", iloc, errs) then | 208 if not validate(schema["else"], data, root, sloc .. "/else", iloc, errs) then |
209 table.insert(errs, mkerr(sloc .. "/else", iloc, "did not match subschema")) | 209 table.insert(errs, mkerr(sloc .. "/else", iloc, "did not match subschema")) |
210 return false, errs | 210 return false, errs |
211 end | 211 end |
212 end | 212 end |