# HG changeset patch # User Kim Alvefur # Date 1635418824 -7200 # Node ID d30c81b875f2e98c1cc057257c1ed83936f94fa3 # Parent b8b889ba8d2746fdb8be8ca86c2b92fbe66225a2 util.dataforms: Ensure larger integers are serialized as such Assumes that most number fields are integers, as most numeric types listed in XEP-0122 are, as are all such fields in Prosody as of this. Otherwise %g produces something like 1.1259e+15 diff -r b8b889ba8d27 -r d30c81b875f2 spec/util_dataforms_spec.lua --- a/spec/util_dataforms_spec.lua Tue Oct 26 15:41:54 2021 +0200 +++ b/spec/util_dataforms_spec.lua Thu Oct 28 13:00:24 2021 +0200 @@ -458,6 +458,12 @@ assert.table(e); assert.string(e.number); end); + + it("serializes largeer ints okay", function () + local x = f:form{number=1125899906842624} + assert.equal("1125899906842624", x:find("field/value#")) + end); + end) describe("datetime", function () diff -r b8b889ba8d27 -r d30c81b875f2 util/dataforms.lua --- a/util/dataforms.lua Tue Oct 26 15:41:54 2021 +0200 +++ b/util/dataforms.lua Thu Oct 28 13:00:24 2021 +0200 @@ -107,8 +107,10 @@ value = datetime.datetime(value); elseif field_type == "boolean" then value = value ~= 0; + elseif field.datatype == "xs:double" or field.datatype == "xs:decimal" then + value = ("%f"):format(value); else - value = ("%g"):format(value); + value = ("%d"):format(value); end end -- Add value, depending on type