Changeset

13085:0e17cb78264f

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.
author Kim Alvefur <zash@zash.se>
date Sat, 22 Apr 2023 12:48:51 +0200
parents 13084:87f646e353cf
children 13086:42ea593bfa8d
files teal-src/prosody/util/jsonschema.tl util/jsonschema.lua
diffstat 2 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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