mod_adhoc: Add support for commands only executable by global administrators
[prosody.git] / util / json.lua
index 40939bb4626f80366c8d037f1f78cff5fa1992d7..cfa84a4b24b88bf6c7daf41a1754492cfef261be 100644 (file)
@@ -134,12 +134,14 @@ end
 
 
 function json.decode(json)
+       json = json.." "; -- appending a space ensures valid json wouldn't touch EOF
        local pos = 1;
        local current = {};
        local stack = {};
        local ch, peek;
        local function next()
                ch = json:sub(pos, pos);
+               if ch == "" then error("Unexpected EOF"); end
                pos = pos+1;
                peek = json:sub(pos, pos);
                return ch;
@@ -268,7 +270,9 @@ function json.decode(json)
                return tonumber(s);
        end
        local function readmember(t)
+               skipstuff();
                local k = readstring();
+               skipstuff();
                checkandskip(":");
                t[k] = readvalue();
        end