Fix empty string parsing

This commit is contained in:
Foereaper
2022-08-02 17:30:50 +02:00
parent 4b218e7b73
commit ebaed7e301
2 changed files with 22 additions and 2 deletions

View File

@ -3,6 +3,7 @@ local debug = false
local CMH = {} local CMH = {}
local datacache = {} local datacache = {}
local delim = {"", "", "", "", ""} local delim = {"", "", "", "", ""}
local emptyStr = ""
local pck = {REQ = 1, DAT = 2} local pck = {REQ = 1, DAT = 2}
-- HELPERS START -- HELPERS START
@ -49,7 +50,12 @@ local function ParseMessage(str)
-- Convert value to correct type -- Convert value to correct type
for k, v in pairs(valTemp) do for k, v in pairs(valTemp) do
local varType = typeTemp[k] local varType = typeTemp[k]
if(varType == 3) then -- Ints if(varType == 2) then -- Strings
-- Special case for empty string parsing
if(v == emptyStr) then
v = ""
end
elseif(varType == 3) then -- Ints
v = tonumber(v) v = tonumber(v)
elseif(varType == 4) then -- Tables elseif(varType == 4) then -- Tables
v = Smallfolk.loads(v, #v) v = Smallfolk.loads(v, #v)
@ -72,6 +78,10 @@ local function ProcessVariables(reqId, ...)
for _, v in pairs(arg) do for _, v in pairs(arg) do
if(type(v) == "string") then if(type(v) == "string") then
-- Special case for empty string parsing
if(#v == 0) then
msg = msg .. emptyStr
end
msg = msg .. delim[2] msg = msg .. delim[2]
elseif(type(v) == "number") then elseif(type(v) == "number") then
msg = msg .. delim[3] msg = msg .. delim[3]

View File

@ -5,6 +5,7 @@ local debug = false
local SMH = {} local SMH = {}
local datacache = {} local datacache = {}
local delim = {"", "", "", "", ""} local delim = {"", "", "", "", ""}
local emptyStr = ""
local pck = {REQ = 1, DAT = 2} local pck = {REQ = 1, DAT = 2}
-- HELPERS START -- HELPERS START
@ -51,7 +52,12 @@ local function ParseMessage(str)
-- Convert value to correct type -- Convert value to correct type
for k, v in pairs(valTemp) do for k, v in pairs(valTemp) do
local varType = typeTemp[k] local varType = typeTemp[k]
if(varType == 3) then -- Ints if(varType == 2) then -- strings
-- special case for empty string parsing
if(v == emptyStr) then
v = ""
end
elseif(varType == 3) then -- Ints
v = tonumber(v) v = tonumber(v)
elseif(varType == 4) then -- Tables elseif(varType == 4) then -- Tables
v = smallfolk.loads(v) v = smallfolk.loads(v)
@ -74,6 +80,10 @@ local function ProcessVariables(sender, reqId, ...)
for _, v in pairs(arg) do for _, v in pairs(arg) do
if(type(v) == "string") then if(type(v) == "string") then
-- Special case for empty string parsing
if(#v == 0) then
msg = msg .. emptyStr
end
msg = msg .. delim[2] msg = msg .. delim[2]
elseif(type(v) == "number") then elseif(type(v) == "number") then
msg = msg .. delim[3] msg = msg .. delim[3]