From d0b6d2010c6badde88a1493ea67fc19d94ccff4c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 23 Apr 2020 18:16:36 +0200 Subject: util.rsm: Fix passing number as attribute --- util/rsm.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'util/rsm.lua') diff --git a/util/rsm.lua b/util/rsm.lua index 40a78fb5..b5afd62a 100644 --- a/util/rsm.lua +++ b/util/rsm.lua @@ -11,9 +11,14 @@ local stanza = require"util.stanza".stanza; local tostring, tonumber = tostring, tonumber; +local s_format = string.format; local type = type; local pairs = pairs; +local function inttostr(n) + return s_format("%d", n); +end + local xmlns_rsm = 'http://jabber.org/protocol/rsm'; local element_parsers = {}; @@ -45,7 +50,7 @@ end local element_generators = setmetatable({ first = function(st, data) if type(data) == "table" then - st:tag("first", { index = data.index }):text(data[1]):up(); + st:tag("first", { index = inttostr(data.index) }):text(data[1]):up(); else st:tag("first"):text(tostring(data)):up(); end -- cgit v1.2.3 From e39789a5fff23500a7ff393ea67d7bf80175d9be Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 23 Apr 2020 18:40:57 +0200 Subject: util.rsm: Explicitly serialize numbers in correct format --- util/rsm.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'util/rsm.lua') diff --git a/util/rsm.lua b/util/rsm.lua index b5afd62a..aade3c19 100644 --- a/util/rsm.lua +++ b/util/rsm.lua @@ -61,7 +61,13 @@ local element_generators = setmetatable({ else st:tag("before"):text(tostring(data)):up(); end - end + end; + max = function (st, data) + st:tag("max"):text(inttostr(data)):up(); + end; + count = function (st, data) + st:tag("count"):text(inttostr(data)):up(); + end; }, { __index = function(_, name) return function(st, data) -- cgit v1.2.3 From 40788f772440e610aa50936e330f5a067ae6fd58 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Thu, 23 Apr 2020 18:42:47 +0200 Subject: util.rsm: Don't convert values to strings that should already be strings Causes util.stanza to throw an error, which helps detect mistakes --- util/rsm.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'util/rsm.lua') diff --git a/util/rsm.lua b/util/rsm.lua index aade3c19..ad725d76 100644 --- a/util/rsm.lua +++ b/util/rsm.lua @@ -10,7 +10,7 @@ -- local stanza = require"util.stanza".stanza; -local tostring, tonumber = tostring, tonumber; +local tonumber = tonumber; local s_format = string.format; local type = type; local pairs = pairs; @@ -52,14 +52,14 @@ local element_generators = setmetatable({ if type(data) == "table" then st:tag("first", { index = inttostr(data.index) }):text(data[1]):up(); else - st:tag("first"):text(tostring(data)):up(); + st:tag("first"):text(data):up(); end end; before = function(st, data) if data == true then st:tag("before"):up(); else - st:tag("before"):text(tostring(data)):up(); + st:tag("before"):text(data):up(); end end; max = function (st, data) @@ -71,7 +71,7 @@ local element_generators = setmetatable({ }, { __index = function(_, name) return function(st, data) - st:tag(name):text(tostring(data)):up(); + st:tag(name):text(data):up(); end end; }); -- cgit v1.2.3