Diff

util/json.lua @ 4284:20979f124ad9

util.json: Fixed handling of truncated JSON.
author Waqas Hussain <waqas20@gmail.com>
date Thu, 02 Jun 2011 05:36:15 +0500
parent 4147:7f119ebcf55f
child 4404:5356664ef9d4
line wrap: on
line diff
--- 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;