On 7/8/2013 12:56 AM, Philipp Gesang wrote:
Hi,
the JSON parser handles backslash escapes improperly. Example:
local data = [[ { "escapes" : "(\")(\\)(\b)(\f)(\n)(\r)(\t)", "invalid" : "\'\v" } ]] local stuff = utilities.json.tolua (data) inspect(stuff)
Currently it chokes on double quotes and treats the other escapes like Lua. Fix suggestion attached.
local escapes = { -- ["\\"] = "\\", -- lua will escape these -- ["/"] = "/", -- no need to escape this one ["b"] = "\010", ["f"] = "\014", ["n"] = "\n", ["r"] = "\r", ["t"] = "\t", } local escape_un = C(P("\\u") / "0x" * S("09","AF","af")) / function(s) return utfchar(tonumber(s)) end local escape_bs = P([[\]]) / "" * (P(1) / escapes) -- if not found then P(1) is returned i.e. the to be escaped char local jstring = dquote * Cs((escape_un + escape_bs + (1-dquote))^0) * dquote
Best regards, Philipp
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
-- ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------