From 79147fcf9f0e29ef6fa073a37fc7fa571e4cc6df Mon Sep 17 00:00:00 2001 From: FranciscoDA Date: Tue, 20 Mar 2018 09:04:36 -0300 Subject: [PATCH] fix unicode character decoding in json strings --- lualibs-util-jsn.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lualibs-util-jsn.lua b/lualibs-util-jsn.lua index e835c07..fce3621 100644 --- a/lualibs-util-jsn.lua +++ b/lualibs-util-jsn.lua @@ -38,6 +38,7 @@ local rparent = P("]") local comma = P(",") local colon = P(":") local dquote = P('"') +local hexdigit = S("0123456789abcdefABCDEF") local whitespace = lpeg.patterns.whitespace local optionalws = whitespace^0 @@ -52,7 +53,8 @@ local escapes = { ["t"] = "\t", } -local escape_un = C(P("\\u") / "0x" * S("09","AF","af")) / function(s) return utfchar(tonumber(s)) end +local escape_un = Cs(P"\\u" / "0x" * hexdigit * 3) / 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