Changeset

4284:20979f124ad9

util.json: Fixed handling of truncated JSON.
author Waqas Hussain <waqas20@gmail.com>
date Thu, 02 Jun 2011 05:36:15 +0500
parents 4282:f5a46b73432b
children 4285:c806a599224a
files util/json.lua
diffstat 1 files changed, 2 insertions(+), 0 deletions(-) [+]
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;