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.
--- 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
--- 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