Software /
code /
prosody
Comparison
util/jsonschema.lua @ 13088:0fbb2b3fd4c0
util.jsonschema: Fix UTF-8ness of 'minLength' and 'maxLength'
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 23 Apr 2023 10:42:07 +0200 |
parent | 13087:5d3e8a226840 |
child | 13162:6140aa67c618 |
comparison
equal
deleted
inserted
replaced
13087:5d3e8a226840 | 13088:0fbb2b3fd4c0 |
---|---|
1 -- This file is generated from teal-src/util/jsonschema.lua | 1 -- This file is generated from teal-src/util/jsonschema.lua |
2 | 2 |
3 local m_type = function(n) | 3 local m_type = function(n) |
4 return type(n) == "number" and n % 1 == 0 and n <= 9007199254740992 and n >= -9007199254740992 and "integer" or "float"; | 4 return type(n) == "number" and n % 1 == 0 and n <= 9007199254740992 and n >= -9007199254740992 and "integer" or "float"; |
5 end; | |
6 | |
7 local utf8 = rawget(_G, "utf8") or require("prosody.util.encodings").utf8; | |
8 local utf8_len = utf8.len or function(s) | |
9 local _, count = s:gsub("[%z\001-\127\194-\253][\128-\191]*", ""); | |
10 return count | |
5 end; | 11 end; |
6 local json = require("prosody.util.json") | 12 local json = require("prosody.util.json") |
7 local null = json.null; | 13 local null = json.null; |
8 | 14 |
9 local pointer = require("prosody.util.jsonpointer") | 15 local pointer = require("prosody.util.jsonpointer") |
101 return false | 107 return false |
102 end | 108 end |
103 end | 109 end |
104 | 110 |
105 if type(data) == "string" then | 111 if type(data) == "string" then |
106 if schema.maxLength and #data > schema.maxLength then | 112 if schema.maxLength and utf8_len(data) > schema.maxLength then |
107 return false | 113 return false |
108 end | 114 end |
109 if schema.minLength and #data < schema.minLength then | 115 if schema.minLength and utf8_len(data) < schema.minLength then |
110 return false | 116 return false |
111 end | 117 end |
112 if schema.luaPattern and not data:match(schema.luaPattern) then | 118 if schema.luaPattern and not data:match(schema.luaPattern) then |
113 return false | 119 return false |
114 end | 120 end |