diff options
author | Kim Alvefur <zash@zash.se> | 2021-03-23 23:55:33 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-03-23 23:55:33 +0100 |
commit | 13185a16ae4306fc13a45713381f0487c8e11526 (patch) | |
tree | 46e6d1dbb27bfd51c507667324223216d0b2c58b | |
parent | 2ae58ee422d6ed8aee0efe99139c5b19790d104f (diff) | |
download | prosody-13185a16ae4306fc13a45713381f0487c8e11526.tar.gz prosody-13185a16ae4306fc13a45713381f0487c8e11526.zip |
util.datamapper: Fix error on attempt to coerce nil to something
Turns falsy values into nil instead of nothing, which ensures this
function always has 1 return value, or table.insert({}) complains. Would
still happen on some unexpected input, but that's actually a good thing.
-rw-r--r-- | teal-src/util/datamapper.tl | 1 | ||||
-rw-r--r-- | util/datamapper.lua | 3 |
2 files changed, 4 insertions, 0 deletions
diff --git a/teal-src/util/datamapper.tl b/teal-src/util/datamapper.tl index 0d757800..99431f86 100644 --- a/teal-src/util/datamapper.tl +++ b/teal-src/util/datamapper.tl @@ -37,6 +37,7 @@ local function toboolean ( s : string ) : boolean end local function totype(t : json_type_name, s : string) : any + if not s then return nil end if t == "string" then return s; elseif t == "boolean" then diff --git a/util/datamapper.lua b/util/datamapper.lua index 7aa916bc..68c09434 100644 --- a/util/datamapper.lua +++ b/util/datamapper.lua @@ -13,6 +13,9 @@ local function toboolean(s) end local function totype(t, s) + if not s then + return nil + end if t == "string" then return s elseif t == "boolean" then |