util/json.lua
changeset 4284 20979f124ad9
parent 4147 7f119ebcf55f
child 4404 5356664ef9d4
--- a/util/json.lua	Thu Jun 02 00:26:23 2011 +0100
+++ b/util/json.lua	Thu Jun 02 05:36:15 2011 +0500
@@ -134,12 +134,14 @@
 
 
 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;