aboutsummaryrefslogtreecommitdiffstats
path: root/util/dataforms.lua
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2020-09-30 09:50:33 +0100
committerMatthew Wild <mwild1@gmail.com>2020-09-30 09:50:33 +0100
commit785c20f6ee7e61a5a91a8b6259623bc2a2bbffaa (patch)
tree3a37db7b805b1555d08cc61c7938cf512ff35ce0 /util/dataforms.lua
parente55d037cdf89efac99c6144b381c9fa880f7fb93 (diff)
parentb80ff2ae4f86aa26e055890a8284b55170ef2056 (diff)
downloadprosody-785c20f6ee7e61a5a91a8b6259623bc2a2bbffaa.tar.gz
prosody-785c20f6ee7e61a5a91a8b6259623bc2a2bbffaa.zip
Merge 0.11->trunk
Diffstat (limited to 'util/dataforms.lua')
-rw-r--r--util/dataforms.lua16
1 files changed, 14 insertions, 2 deletions
diff --git a/util/dataforms.lua b/util/dataforms.lua
index 052d6a55..efb13ac9 100644
--- a/util/dataforms.lua
+++ b/util/dataforms.lua
@@ -10,6 +10,7 @@ local setmetatable = setmetatable;
local ipairs = ipairs;
local type, next = type, next;
local tonumber = tonumber;
+local tostring = tostring;
local t_concat = table.concat;
local st = require "util.stanza";
local jid_prep = require "util.jid".prep;
@@ -54,6 +55,12 @@ function form_t.form(layout, data, formtype)
if formtype == "form" and field.datatype then
form:tag("validate", { xmlns = xmlns_validate, datatype = field.datatype });
+ if field.range_min or field.range_max then
+ form:tag("range", {
+ min = field.range_min and tostring(field.range_min),
+ max = field.range_max and tostring(field.range_max),
+ }):up();
+ end
-- <basic/> assumed
form:up();
end
@@ -136,7 +143,7 @@ function form_t.form(layout, data, formtype)
local media = field.media;
if media then
- form:tag("media", { xmlns = "urn:xmpp:media-element", height = media.height, width = media.width });
+ form:tag("media", { xmlns = "urn:xmpp:media-element", height = ("%g"):format(media.height), width = ("%g"):format(media.width) });
for _, val in ipairs(media) do
form:tag("uri", { type = val.type }):text(val.uri):up()
end
@@ -290,13 +297,18 @@ field_readers["hidden"] =
end
data_validators["xs:integer"] =
- function (data)
+ function (data, field)
local n = tonumber(data);
if not n then
return false, "not a number";
elseif n % 1 ~= 0 then
return false, "not an integer";
end
+ if field.range_max and n > field.range_max then
+ return false, "out of bounds";
+ elseif field.range_min and n < field.range_min then
+ return false, "out of bounds";
+ end
return true, n;
end