········· > 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 Fine with me! Best, Philipp