Package: lua-json
Version: 1.3.1-1
Followup-For: Bug #719519

Dear Maintainer,

I stumbled upon this bug today, and although being an RC bug, we most certainly
won't get 1.3.2 in jessie [1].

[1]: https://release.debian.org/jessie/freeze_policy.html

FWIW, there are not many upstream commits between 1.3.1 and 1.3.2, and the
attached patch (taken from upstream) works for me with 1.3.1-1 from
unstable. By including it, I can build a deb package, doing a require("json")
and parse some examplary JSON.

 - Roland
Author: Thomas Harning Jr <[email protected]>
Date:   Fri Apr 12 15:28:52 2013 -0400
Origin: https://github.com/harningt/luajson/commit/1edf209
Applied-Upstream: yes
Subject: fix compatibility with lpeg 0.12 by closing off 0-length captures in loops

diff --git a/lua/json/decode/strings.lua b/lua/json/decode/strings.lua
index 1e91836..cb3b5cc 100644
--- a/lua/json/decode/strings.lua
+++ b/lua/json/decode/strings.lua
@@ -18,11 +18,11 @@ local _ENV = nil
 
 local function get_error(item)
 	local fmt_string = item .. " in string [%q] @ %i:%i"
-	return function(data, index)
+	return lpeg.P(function(data, index)
 		local line, line_index, bad_char, last_line = util.get_invalid_character_info(data, index)
 		local err = fmt_string:format(bad_char, line, line_index)
 		error(err)
-	end
+	end) * 1
 end
 
 local bad_unicode   = get_error("Illegal unicode escape")
@@ -67,8 +67,8 @@ local function decodeX(code)
 end
 
 local doSimpleSub = lpeg.C(lpeg.S("'\"\\/bfnrtvz")) / knownReplacements
-local doUniSub = lpeg.P('u') * (lpeg.C(util.hexpair) * lpeg.C(util.hexpair) + lpeg.P(bad_unicode))
-local doXSub = lpeg.P('x') * (lpeg.C(util.hexpair) + lpeg.P(bad_hex))
+local doUniSub = lpeg.P('u') * (lpeg.C(util.hexpair) * lpeg.C(util.hexpair) + bad_unicode)
+local doXSub = lpeg.P('x') * (lpeg.C(util.hexpair) + bad_hex)
 
 local defaultOptions = {
 	badChars = '',
@@ -93,8 +93,8 @@ end
 
 local function buildCaptureString(quote, badChars, escapeMatch)
 	local captureChar = (1 - lpeg.S("\\" .. badChars .. quote)) + (lpeg.P("\\") / "" * escapeMatch)
-	captureChar = captureChar + (-#lpeg.P(quote) * lpeg.P(bad_character))
-	local captureString = captureChar^0
+	-- During error, force end
+	local captureString = captureChar^0 + (-#lpeg.P(quote) * bad_character + -1)
 	return lpeg.P(quote) * lpeg.Cs(captureString) * lpeg.P(quote)
 end
 
@@ -111,7 +111,7 @@ local function generateLexer(options)
 		escapeMatch = escapeMatch + options.additionalEscapes
 	end
 	if options.escapeCheck then
-		escapeMatch = options.escapeCheck * escapeMatch + lpeg.P(bad_escape)
+		escapeMatch = options.escapeCheck * escapeMatch + bad_escape
 	end
 	local captureString
 	for i = 1, #quotes do
diff --git a/lua/json/decode/util.lua b/lua/json/decode/util.lua
index 857bf0c..b90c0b7 100644
--- a/lua/json/decode/util.lua
+++ b/lua/json/decode/util.lua
@@ -33,7 +33,7 @@ local function build_report(msg)
 		local line, line_index, bad_char, last_line = get_invalid_character_info(data, pos)
 		local text = fmt:format(pos, line, line_index, bad_char, last_line)
 		error(text)
-	end)
+	end) * 1
 end
 local function unexpected()
 	local msg = "unexpected character"

Reply via email to