aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-04-23 10:42:07 +0200
committerKim Alvefur <zash@zash.se>2023-04-23 10:42:07 +0200
commit693ac009db93fd14d15e465f5e11a77485037b09 (patch)
tree397256cf9f511717c4032cbb0e0314bc48a95465 /util
parent3621b8ce9168d833303bc8090302a77dcd76e1fd (diff)
downloadprosody-693ac009db93fd14d15e465f5e11a77485037b09.tar.gz
prosody-693ac009db93fd14d15e465f5e11a77485037b09.zip
util.jsonschema: Fix UTF-8ness of 'minLength' and 'maxLength'
Diffstat (limited to 'util')
-rw-r--r--util/jsonschema.lua10
1 files changed, 8 insertions, 2 deletions
diff --git a/util/jsonschema.lua b/util/jsonschema.lua
index 51ad506f..c67fb744 100644
--- a/util/jsonschema.lua
+++ b/util/jsonschema.lua
@@ -3,6 +3,12 @@
local m_type = function(n)
return type(n) == "number" and n % 1 == 0 and n <= 9007199254740992 and n >= -9007199254740992 and "integer" or "float";
end;
+
+local utf8 = rawget(_G, "utf8") or require("prosody.util.encodings").utf8;
+local utf8_len = utf8.len or function(s)
+ local _, count = s:gsub("[%z\001-\127\194-\253][\128-\191]*", "");
+ return count
+end;
local json = require("prosody.util.json")
local null = json.null;
@@ -103,10 +109,10 @@ function complex_validate(schema, data, root)
end
if type(data) == "string" then
- if schema.maxLength and #data > schema.maxLength then
+ if schema.maxLength and utf8_len(data) > schema.maxLength then
return false
end
- if schema.minLength and #data < schema.minLength then
+ if schema.minLength and utf8_len(data) < schema.minLength then
return false
end
if schema.luaPattern and not data:match(schema.luaPattern) then