# HG changeset patch # User Kim Alvefur # Date 1682160531 -7200 # Node ID 0e17cb78264f1a345482b2e23c62ea2ff74b4f1d # Parent 87f646e353cf3749e25ded418017cb5656e04d0e util.jsonschema: Implement 'luaPattern' - Lua variant of 'pattern' Like 'pattern' but uses Lua patterns instead of Regular Expressions, since only a subset of regex are also valid Lua patterns. diff -r 87f646e353cf -r 0e17cb78264f teal-src/prosody/util/jsonschema.tl --- a/teal-src/prosody/util/jsonschema.tl Sat Apr 22 12:14:29 2023 +0200 +++ b/teal-src/prosody/util/jsonschema.tl Sat Apr 22 12:48:51 2023 +0200 @@ -98,6 +98,7 @@ -- for Lua luaPatternProperties: { string : schema_t } + luaPattern : string -- xml record xml_t @@ -225,6 +226,9 @@ if schema.minLength and #data < schema.minLength then return false end + if schema.luaPattern and not data:match(schema.luaPattern) then + return false + end end if data is number then diff -r 87f646e353cf -r 0e17cb78264f util/jsonschema.lua --- a/util/jsonschema.lua Sat Apr 22 12:14:29 2023 +0200 +++ b/util/jsonschema.lua Sat Apr 22 12:48:51 2023 +0200 @@ -109,6 +109,9 @@ if schema.minLength and #data < schema.minLength then return false end + if schema.luaPattern and not data:match(schema.luaPattern) then + return false + end end if type(data) == "number" then